Tweaking Compiler Performance in Flex Builder

Using some Eclipse and Java tricks to better manage Flex Builder's memory, and (hopefully) increase compiler performance.

My coworker Axel discovered a nice Eclipse trick the other day. If you go to Window->Preferences->General, there is an option called "Show heap status" (if you don't see it, check out my note at the end of this post). This option is disabled by default. When it is selected, you will notice a bar in the lower right hand corner of the screen indicating Eclipse's current memory usage. If you right-click this bar, there is another option to show the max heap size. Good stuff. The best part is the little trash can button which you can use to force garbage collection to be run. After running Eclipse for a while, this often has a big effect on the memory usage, and runs surprisingly fast on my machine (less than one second).

Overriding the default memory allocation:
After watching the heap's behavior for a day or two I noticed that the start size of the heap (a paltry 64MB) seems to be insufficient for compiling any of my Flex projects. When you do a compile, you will see Java incrementally increase the size of the heap to accommodate. Since there is some overhead in memory allocation, we can optimize this a bit by telling Java how much memory to allocate to the virtual machine when it starts up. You do this by setting the -vmargs flag at the command line.

Try running Eclipse using -vmargs -Xms256M -Xmx512M to set the start heap size at 256mb and max at 512mb (I think the default max is around 256). Take care not to set either of these too high, or it will bog down the rest of your machine... and make sure you have enough memory installed to begin with. I've got 2GB of RAM and I'm not running any other heavy applications alongside Eclipse, so allocating a few hundred extra megs shouldn't be an issue for me.

In Windows, you can set these values using a shortcut. Right click your shortcut to Eclipse and select "Properties". Add the flags after the existing Target (and outside of the quotes). It should look something like this:

"C:\Program Files\eclipse\eclipse.exe" -vmargs -Xms256M -Xmx512M

Memory usage at startup...

Before: heap_before.PNG

After: heap_after.PNG

I don't have any definitive proof that this makes any difference on compiler performance, and results will always vary from one machine to the next, but its a pretty easy trick and has worked great for me so far.

Note:
If you do not see the "Show heap status" option in your preferences (and I don't think you will if you have the standalone version of Flex Builder), you will just have to obtain the plugin manually.

From the Eclipse site:

The Heap Status plug-in shows the current Java heap usage in the status line (total heap and amount used). A button allows you to force a garbage collect. It includes a preference page (Window > Preferences > Workbench > Memory Indicator) which lets you turn it on and off. This plug-in works on Eclipse 2.1, 3.0, 3.0.1 and 3.1.

The Heap Status plug-in can be obtained via the Platform UI team's update site.
Use Help > Software Updates > Find and Install > Search for new features to install > New Remote Site, and give the following as the URL.
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-ui-home/updates

When prompted, choose Yes to restart.

If you don't see the status indicator in the status line, or if the preference page is missing, restart eclipse with the -clean command line option.


About this entry