Is there a performance difference between Javac debug on and off?

JavaPerformanceDebuggingJavac

Java Problem Overview


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.

Java Solutions


Solution 1 - Java

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.

Solution 2 - Java

Turning off debugging alone 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$. :)

Solution 3 - Java

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHorcrux7View Question on Stackoverflow
Solution 1 - JavaPaul de VriezeView Answer on Stackoverflow
Solution 2 - JavaThomas MorgnerView Answer on Stackoverflow
Solution 3 - JavaMaxim VekslerView Answer on Stackoverflow