views:

2103

answers:

4

If I switch on the generating of debug info with Javac then the class files are 20-25% larger. Has this any performance effects on running the Java program? If yes on which conditions and how many. I expect a little impact on loading the classes because the files are larger but this should be minimal.

+12  A: 

In any language, debugging information is meta information. It by its nature increases the size of the object files, thus increasing load time. During execution outside a debugger, this information is actually completely ignored. As outlined (although not clearly) in the JVM spec the debug information is stored outside the bytecode stream. This means that at execution time there is no difference in the class file. If you want to be sure though, try it out :-).

Ps. Often for debugging there is value in turning off optimization. That does have a performance impact.

Paul de Vrieze
Does javac still have -O? Last I remember it was the equivalent of -g:none.
Tom Hawtin - tackline
Correct. Load time is affected but execution time is not.
kohlerm
Indeed the sun java compiler does not have an optimize flag. Optimization mainly happens in the hotspot runtime. Optimizing at compile time may actually hamper hotspots ability to optimize (using full information only available at compile time).
Paul de Vrieze
+3  A: 

Turning off debugging along should not make a difference at all. But once you turn off debugging and turn on optimization, you should see a difference, as this makes some static optimizations at compile time. This way even your hot-spot optimized code gets faster at runtime.

But so far, the tradeoff between getting meaning full stack-traces or having some more user-performance, I always voted for the stack-traces. After all, users are willing to spend 1000$ each year to get a faster machine, but are not willing to spend 15 minutes to give you meaningful error messages to you to solve their problems.

After the years, I'm more willing to value my 15 minutes higher than the user's 1000$. :)

A: 

Please be aware that since JDK1.3 javac ignores any optimization flags, "compile-time optimization is unnecessary"

Maxim Veksler
A: 

No where in the Java website they are talking about -O option; it's pros and cons? I have tried to compile my application with and without debug option. I'm getting some performance improvement while trying without debug option and -O option. (jdk version 1.5)

Nikesh PL