Improving GWT compilation speed

Yesterday we have moved one of our projects from GWT 1.7 to GWT 2.0. And GWT compilation appeared to run slower on my host.

So I’ve started looking for a way to make this process faster.

The initial compilation of the project took 207 seconds and permutation compilation 170 seconds

The main idea of speeding up compilation is to reduce the number of the compiled permutations. Permutation is a combination of the supported browser and locale.

By default permutations for the following browsers are compiled:

  • ie6
  • ie8
  • gecko
  • gecko1_8
  • safari
  • opera

So in case of having three locales – 18 permutations are compiled.

But do we need all these during development? I guess no. Usually you develop within one browser and the rest are used once the development is completed.
So lets reduce the list of the supported browsers by adding the following string in our *.gwt.xml file

<set-property name="user.agent" value="gecko"/>

This reduces the list of browsers to the gecko based ones, like FireFox or SeaMonkey.
Now compilation takes 84 seconds and permutations compilation – 66 seconds. Not too bad, right?

Okay, lets go further.
Lets add draftCompile GWT compiler flag. Since our project is built by Maven – go to pom.xml and put the following string into the configuration section of the GWT plugin:

<draftCompile>true</draftCompile>

This option allows you to skip JavaScript optimization step. And the compilation time reduces to 65 seconds, permutation compilation – 48 seconds.

The next option which I’ve tried – is the localWorkers compilation option. This option specifies the number of parallel processes used to compile GWT permutations. The default value is quite fine and changing it didn’t bring any speed up.

So the last option I’ve tried was reducing permutations count by reducing count of the compiled locales. I’ve specified the following string in my *.gwt.xml file

<set-property name="locale" value="en"/>

So there’s only one english locale compiled. Now we have only one permutation compiling: English locale for Gecko-based browsers. The compilation time reduced to 48 seconds(30 seconds to compile permutations).

All of the results are combined into the table below

Description Compilation (in sec.) Permutation Compilation (in sec.)
Initial 207 170
After specifying user.agent property 84 66
After specifying draftCompile parameter 65 48
After specifying localWorkers parameter 66 48
After specifying locale property 48 30

As you can see – the compilation speed decreased more than 5 times. This difference is really vivid on a smal project and can bring you a huge benefit on a large project.

The following environment was used during the testing: Fedora 13 x86_64, Oracle JDK 1.6.0_20, GWT 2.0.3, Maven 2.1.0.