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

前端 未结 3 953
清歌不尽
清歌不尽 2020-12-02 16:49

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

相关标签:
3条回答
  • 2020-12-02 17:02

    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$. :)

    0 讨论(0)
  • 2020-12-02 17:07

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

    0 讨论(0)
  • 2020-12-02 17:17

    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.

    0 讨论(0)
提交回复
热议问题