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

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.

Asked by: Adrian112 | Posted: 23-01-2022

Answer 1

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.

Answered by: Elise723 | Posted: 24-02-2022

Answer 2

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

Answered by: Alina463 | Posted: 24-02-2022

Answer 3

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

Answered by: Lily925 | Posted: 24-02-2022

Similar questions

java - Is there a performance difference between a for loop and a for-each loop?

What, if any, is the performance difference between the following two loops? for (Object o: objectArrayList) { o.DoSomething(); } and for (int i=0; i<objectArrayList.size(); i++) { objectArrayList.get(i).DoSomething(); }

java - Performance difference between annotating fields or getter methods in Hibernate / JPA

I was curious if anyone had any hard numbers around the performance difference between annotating Entities using private fields instead of public getter methods. I've heard people say that fields are slower because they're called "through reflection" but then again so are the getter methods, no? Hibernate needs to set the accessibility of the field to true before it tries to read it which I can see having some slight...

Vast difference in Java Performance from 1.4 to 1.6

I have observed a great difference in Sun Java performance when code is compiled through jdk1.6 as compared to jdk1.5 or jdk1.4 (over 4 folds) What changes and optimizations have been done? Is there anything worth taking home from these changes which will help to boost our application performance. Thanks for replying

java - Is there a performance difference between these two pieces of code?

Is there a performance difference between these two pieces of code? My gut feeling is that the second option is slower, as the Cell object has to be constructed each time, but I like the idea of returning a Cell. Option One: //Call to method initiTextDefaultCell(borders); iTextTable.setDefaultCell(iTextDefaultCell); //Other code... private void initiTextDefaultCell(boolean borders) { if (!border...

Java for loop vs. while loop. Performance difference?

Assume i have the following code, there are three for loop to do something. Would it run fast if i change the most outer for loop to while loop? thanks~~ int length = 200; int test = 0; int[] input = new int[10]; for(int i = 1; i <= length; i++) { for (int j = 0; j <=length - i; j++) { for (int k = 0; k < length - 1; k++) { test = test + input[j + k]; } ...

What is the performance difference, if any, between if(!foo) and if(foo == false) in Java?

Logically, if(!foo) and if(foo == false) are equivalent. How are they represented in Java? Is there any difference between the two after compilation, either in the bytecode or in performance? I was unable to find an answer in the JLS, and searching brought up a lot of results about = vs. == typos and ==/equals() behavior. (In this case, the symbols hampered my searching; for future searchers, ...

java - Difference in performance between Stax and DOM parsing

I have been using DOM for a long time and as such DOM parsing performance wise has been pretty good. Even when dealing with XML of about 4-7 MB the parsing has been fast. The issue we face with DOM is the memory footprint which become huge as soon as we start dealing with large XMLs. Lately I tried moving to Stax (Streaming parsers for XML) which are supposed top be second generation parsers (reading about Stax it ...

java - Performance difference between Iterator Class and foreach construct

I have the following code running, but I sometimes get some sort of concurrency exception when running it. ArrayList<Mob> carriers = new ArrayList<Mob>(); ArrayList<Mob> mobs = new ArrayList<Mob>(); ... for (Mob carrier : carriers){ for (Mob mob : mobs){ checkInfections (carrier, mob); } } I refactored it to solve the concurrency problem, but it did...

java - Is there a performance difference between using 20 jars and using only one repacking them?

My program uses around 20 jars (for a total size of about 30mb). For now, they are all added to the classpath for the released version, and all jars are deployed with the rest. Would there be a performance impact if I was unpacking them and repacking them into one jar?

java - Performance difference of Native SQL(using MySQL) vs using Hibernate ORM?

I am using Spring MVC for an application that involved a multilevel back end for management and a customer/member front end. The project was initially started with no framework and simple native JDBC calls for database access. As the project has grown significantly(as they always do) I have made more significant database calls, sometimes querying large selection sizes. I am doing what I can to treat my db c...

Performance question: Fastest way to convert hexadecimal char to its number value in Java?

I want to convert from char representing a hexadecimal value (in upper or lower case) to byte, like '0'->0, '1' -> 1, 'A' -> 10, 'a' -> 10, 'f' -> 15 etc... I will be calling this method extremely often, so performance is important. Is there a faster way than to use a pre-initialized HashMap<Character,Byte> to get the value from? Answer

performance - Java very large heap sizes

Closed. This question needs to be more focused. It ...

performance - Size of a byte in memory - Java

I have heard mixed opinions over the amount of memory that a byte takes up in a java program. I am aware you can store no more than +127 in a java byte, and the documentation says that a byte is only 8 bits but here I am told that it actua...

java - How to improve Netbeans performance?

Is there a real way to get Netbeans to load and work faster? It is too slow and gets worse when you have been coding for some time. It eats all my RAM. I am on a Windows machine, specifically Windows Server 2008 Datacenter Edition x64, 4Gb of RAM, 3Ghz Core 2 Duo processor, etc. I am using the x64 JDK. I use the NOD32 Antivirus since for me it is the best in machine performance. In Task Manage...

java - Is there a performance difference between a for loop and a for-each loop?

What, if any, is the performance difference between the following two loops? for (Object o: objectArrayList) { o.DoSomething(); } and for (int i=0; i<objectArrayList.size(); i++) { objectArrayList.get(i).DoSomething(); }

performance - Java File Cursor

Is there some library for using some sort of cursor over a file? I have to read big files, but can't afford to read them all at once into memory. I'm aware of java.nio, but I want to use a higher level API. A little backgrond: I have a tool written in GWT that analyzes submitted xml documents and then pretty prints the xml, among other things. Currently I'm writing the pretty printed xml to a temp file (my lib woul...

performance - Accelerate 2D images in Java *without* disturbing JMenus

Already implemented performance boosters : - Get compatible image of GraphicsConfiguration to draw on - Enable OpenGL pipeline in 1.5: Not possible due to severe artifacts So far I am fine, the main profiled bottleneck of the program is drawing an image with several thousand tiles. Unfortunately it is not regular, else I simply could set pixels and scale them. I accerelated the image with VolatileImages and own ren...

performance - Measuring Java execution time, memory usage and CPU load for a code segment

For a particular segment of Java code, I'd like to measure: Execution time (most likely thread execution time) Memory usage CPU load (specifically attributable to the code segment) I'm a relative Java novice and am not familiar with how this might be achieved. I've been referred to

Can anyone quantify performance differences between C++ and Java?

Java was initially slow before the JIT but today performance is pretty close to C++. I want to know if someone has done measurable performance comparisons between the two languages? Where does Java fall short when compared to C++? Java provides many productivity gains to developers so they can write applications much quicker because of garbage college, lack of pointers, etc. Applications such as Firefox, Webkit ...

performance - ArrayList vs. Vectors in Java if thread safety isn't a concern

Is there really that much of a difference between the performance of Vector and ArrayList? Is it good practice to use ArrayLists at all times when thread safety isn't an issue?

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)