Speeding up GWT compilation with Ant’s parallel task

November 27th, 2008 Alex Moffat Posted in GWT | 6 Comments »

For Blueprint we use Ant to invoke the GWT compiler even though the rest of the build process is controlled by maven. If you’re also using Ant the technique I describe is a simple way to get a nice reduction in compilation time.

In our build.xml file we have a generic CompileGWTModule target that is invoked multiple times with the antcall task to compile the different GWT modules in the application. So we end up with something like this


  <antcall target="CompileGWTModule">
     <param name="gwt.module" value="LoginPage"/>
  </antcall>
  <antcall target="CompileGWTModule">
     <param name="gwt.module" value="ProcessPage"/>
  </antcall>
  <antcall target="CompileGWTModule">
     <param name="gwt.module" value="ProjectPage"/>
  </antcall>
  ....

On my MacBook Pro the GWT compilation process takes about eight minutes to complete when building all pages for all browsers. On my desktop it takes about seven and three quarter minutes. Ant has a parallel task that will invoke the tasks it surrounds in parallel. I simply wrapped the calls to CompileGWTModule in a parallel element like this


  <parallel threadsPerProcessor="1">
    <antcall target="CompileGWTModule">
       <param name="gwt.module" value="LoginPage"/>
    </antcall>
    <antcall target="CompileGWTModule">
       <param name="gwt.module" value="ProcessPage"/>
    </antcall>
    <antcall target="CompileGWTModule">
       <param name="gwt.module" value="ProjectPage"/>
    </antcall>
    ....
  </parallel>

The threadsPerProcessor attribute tells the task to use one thread for each processor/core in the machine. With these settings the same compilation takes about four and a quarter minutes on the dual core MacBook and two and three quarter minutes on the four core desktop. That’s significantly quicker.

Of course for maximum reduction in compilation time you should also

  • Use hosted mode as much as possible so that you don’t compile when you don’t need to.
  • Edit your GWT module xml files so that when you’re testing you only compile for the browser you need to test for. Using a common module xml file inherited by all your others makes this easy to do.
  • Structure your build scripts so that you can choose which modules you compile.

6 Responses to “Speeding up GWT compilation with Ant’s parallel task”

  1. Interesting!

    I was thinking about a way to skip the Javascript generation completely. For hosted mode you only need your public content, the bootstrap js file (an old copy will do), history.html, hosted.html and RPC serialization files.

    The later are the problem as you need real ones matching your current RPC server endpoints. But hosted mode will never look at the generated Javascript files containing the compiled client code.

    It would be nice if the compiler had a ‘-bare_minimim_for_hosted_mode’ option and skip all Javascript generation. If you know your are in the middle of development and will use hosted mode exclusively thats all you need. If you want to you could press the Compile button in hosted mode later…

    Christian

  2. Hosted mode is probably not far off that now. I know it only generates a permutation for the single user agent value for the embedded browser it’s using. It probably also generates the RPC serialization files. I’m not sure it does any JavaScript generation, or that it actually needs any. It would be an interesting topic to investigate.

  3. [...] see what effect this has on compile times for Blueprint. The compile process for Blueprint already compiles multiple pages in parallel using the ant parallel task so it’s interesting to see how this interacts with parallel compilation of multiple [...]

  4. [...] and the presence of two GWT modules plus another build compelled me to resurect some old-school Ant parallelization to stack as much work as possible during the build. With a bit of tweaking it’s easy to have [...]

  5. Kovalenko Oleg Says:

    Thanks!

  6. [...] Lombardi’s take on parallel and local threads [...]

Leave a Reply