Speeding up GWT compilation speeds in a LibGDX project

 

On thing i’ve discovered working with GWT these past few weeks is, it’s slow… very very very slow.  I am developing on a newer laptop running a Haswell processor and SSD and my compilation times look like this:

image

 

254 seconds per compile is simply not tenable, especially during development.  You can avoid a compilation by working in DevMode, but this is exceedingly fragile at times.  As a result, I wanted to look into a way of speeding the process up.  Fortunately it’s a fairly simple process in the end.

 

The first culprit is the “Compiling permutation X” bit.  By default it is going to compile a version for every supported browser.  For release this is obviously advantageous, but during development it is bringing compile times to a crawl.  Fortunately, you only really need to develop for whatever browser you are testing in.  If you are working with a LibGDX project locate the file GwtDefinition.gwt.xml in the –html project.  There is one in the base project too, but that is not the file you are looking for.  It should look like this:

image

 

Edit that file to look like this:

 

<?xml version="1.0" encoding="UTF-8"?>  <!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit trunk//EN"       "http://google-web-toolkit.googlecode.com/svn/trunk/distro-source/core/src/gwt-module.dtd">  <module>      <inherits name='com.badlogic.gdx.backends.gdx_backends_gwt' />      <inherits name='InputDemo' />      <entry-point class='input.gamefromscratch.com.client.GwtLauncher' />      <set-configuration-property name="gdx.assetpath" value="../input-android/assets" />      <set-property name="user.agent" value="safari"/>  </module>

 

The line highlighted in yellow is the one you are interested in.  Basically you provide an entry for each browser you want GWT to compile for.  In my case I am working in Chrome which (oddly enough) doesn’t have it’s own user agent ( in the form value=”safari,ie9,other_values_here” ).  As Safari and Chrome have a common ancestor in Webkit, this user agent works.  You can also specify values for FireFox ( gecko ) and IE.  By building for just a single browser, we see a massive speedup.  In my after making the above change:

image

 

Down to 53 seconds… much better, but still far to long in my humble opinion.

 

Then one other idea struck me… I’m running a 32bit version of the JDK ( because so many tools still don’t play well with JDK7, FlashDevelop being the biggest ), so after a great deal of effort, I got and configured a 64 bit JDK and version of Eclipse.  Coincidentally, Eclipse really doesn’t seem to like sharing a workspace between 32 and 64bit installs!  Once I eventually got it working ( an hour and a half later… oh Eclipse, I so hate you ), I ran the GWT compiler again:

 

 image

 

31.5 seconds, almost a halving in development time.  So either Java 7, 64bit or possibly both resulted in a large decrease in compile time.

 

There is one final optimization I found, which is ironically to not optimize.  Just like with C++ compilers, you can create and optimized and unoptimized build.  By default GWT performs a great deal of optimization and during development, this is probably a waste.  Fortunately it can easily be disabled.  When you run a GWT compile, in the options window you can pass an additional parameter, –draftCompile.  It is available under the Advanced tab:

image

 

And the result:

image

17 seconds!  Much much much better!  Coincidentally, playing around with the memory amount available made little to no difference.  I actually experienced slightly slower compilation time when I increased it to 2G ( of 8 available on my machine ).  Obviously the less optimized version is going to run slower, but it shouldn’t be by a huge margin.

 

Remember though, when building for release, you want to re-enable all of these settings!  But for day to day development, 17 seconds is a heck of a lot better than 254s!

Programming


Scroll to Top