How much slower is Java code with debugging enabled?

I am wondering how many performance penalties exist if all the Java code I created had debugging information in it. If there is not so much fine, I could do things like getting very useful information in production, when necessary, without having to recompile.

+3
source share
3 answers

I assume that you are thinking of line numbers and local variable names.

Both debugging additions do not add additional instructions to the bytecode. Therefore, performance should not be affected. Line numbers and variable names are additional tables in class files and are ignored if you are not actually debugging the code.


javac:

-g
    Generate all debugging information, including local variables. 
    By default, only line number and source file information is generated.

-g:none
    Do not generate any debugging information.

-g:{keyword list}
    Generate only some kinds of debugging information, specified by 
    a comma separated list of keywords. Valid keywords are:

    source
        Source file debugging information 
    lines
        Line number debugging information 
    vars
        Local variable debugging information 
+7

. prod, dev , . , , ?

+3

Depends on how you are debugging. If you print information to a console or file, it will definitely take some performance. If you use the registration API, then perhaps you can reduce the granularity, as mentioned by Qwerky, and this should help.

+1
source

Source: https://habr.com/ru/post/1788453/


All Articles