Friday, November 23, 2012

Eclipse - “Show heap status”

One of the problems people complain about when starting with Eclipse is that it is slow. Then if you search the web you are advised to allocate more memory (RAM) to Eclipse (Java), but how much should you really?

Well, it all depends on the size of your project and the plugins that you use. Allocate too little and Java Garbage Collector will consume a lot of CPU going through the heap trying to remove discarded objects to make room for new ones, allocate too much than you system has free (available) and it will swap extensively to disk (“swap” file) to give you more free RAM.

How would you know if you allocated enough to Eclipse or you might need to allocate more (provided that you see you have the free memory available). This is where Eclipse “show heap status” feature comes in handy.

First of all you need to enable it: Windows > Preferences > General > Show heap status. It will show this little graph in the status bar:
  • left area (lighter) is how much heap it uses at the moment.
  • right area (darker if you right-click it and check show “Heap Max”) is how much is available from what pre-allocated (either through –Xms startup parameter or pushed past –Xms towards –Xmx)
  • hover to get the details in a tooltip;
  • click the garbage can to force a Garbage Collection.

Then look at it while using the project (build etc) – if the heap usage goes towards maximum, the colour will turn red showing that it might be struggling. You can force a garbage collection using the “garbage can”, but that’s a workaround just to finish the job instead of having to restart Eclipse. Use it too much and the JVM will pause to force an early GC.

In my example I have both minimum (-Xms) and maximum (-Xmx) heap size set to the same values (384MB) and at that moment was only using 41 MB out of it (it pre-allocated though the minimum from the system at startup). As you will be using the project it will go up and down, as needed and as GC will do it’s job.

[...]
--launcher.XXMaxPermSize
256M
[...]
-vm
C:\Program Files\Java\jdk1.7.0_09\jre\bin\server\jvm.dll
-vmargs
[...]
-Xms384m
-Xmx384m
So why is my eclipse.exe (javaw.exe) process using 600 MB of RAM when I’ve set my heap to 384 MB? It’s because Heap is not everything, there’s also the Permanent Generation (PermGen) and a few other things, so consider those as well when you decide to increase heap. On Windows use a tool like Process Explorer to see all these details – system commit, free RAM, process private bytes, working set etc.

3 comments :

  1. Good post. I keep telling people that Eclipse is not slow, you're just doing it wrong. Most of the time I set -Xmx to 1g

    ReplyDelete
  2. Yeah, it's a shame cause I think Eclipse is a great platform, but it comes with defaults out of the box and it puts most people off. There would be more to try and tune the garbage collector (concurrent mark and sweep, new parallel collector) that can improve things, and there's continuous work done one the platform and it's plugins, which is also great.

    ReplyDelete
  3. Good day :) thanks a lot. It works for me

    ReplyDelete