I found out that most of the time the IDE pauses because of Garbage Collector execution. The subtle little element in design of JVM, which usually does great job in relieving us developers from worrying about memory consumption, and most people are just happy that it does its job well and ignore it most of the time. However, the consequences of running Garbage Collector may surprise us if we simply ignore it.
In short, when GC is running, it pauses execution of the application until it is done freeing the memory. This is for sure unacceptable for real-time systems, where Java is certainly not the number one option. But even in non-critical huge desktop applications, which modern Java IDEs certainly are, the GC may stop the whole application for several seconds. And this may happen several times during the day. You can imagine that with productivity tools like IDEs, this is simply dragging down their "productivity" effect.
A solution is to do some tweaking:
- increase memory for JVM on which the IDE is running (beware that this only reduces frequency of GC being called, but prolongs the execution time of a single GC run - it takes longer to collect garbage from bigger pile...)
- switch default GC engine for a more concurrent engine, which tries to collect garbage continually even between stop-everything-until-done executions of complete GC
The first option is well known to majority of Java programmers - just define reasonable values for MaxPermSize and the family.
The second option, however, is not so well known. The point is that Oracle Java Hotspot JVM provides several alternative GC engines, which we can choose from. And they, unlike the default one, provide continuous garbage collection even between the big GC executions that slow everything down.
G1 Garbage CollectorSince Java 7 update 4, Oracle provides G1 Garbage Collector in JVM.
You may enable it simply with this command line param:
-XX:+UseG1GCFor more info on how to configure G1, see Java Hotspot VM G1 options.
CMS Garbage CollectorIn some benchmarks, older CMS collector outperforms the newer G1 collector.
You may enable it instead of G1 with these options: