Dojo
Dojo

Reputation: 5684

GWT Parallel Compile vs Sequential Compile

I was trying to reduce the time it takes for an ant build to complete. Most of the build time is taken by GWT compiler.

Following ant script is written on the lines of scripts found in official GWT examples. Notice how two GWT modules are being passed to the Complier. When you run this script, the GWT compiler compiles the two modules sequentially.

<target name="gwtc" description="GWT compile to JavaScript">
    <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
        ........
        ........

        <arg value="com.af.gwtmodules.dashboard.Dashboard" />
        <arg value="com.af.gwtmodules.administration.Administration" />
        <arg line=" -localWorkers 16" />
    </java>
</target>

I changed the task to run 2 compile tasks in parallel and in each task I pass only one GWT module to the compiler.

<target name="gwtc" description="GWT compile to JavaScript">
<parallel threadsperprocessor="16">
    <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
        ........
        ........

        <arg value="com.af.gwtmodules.dashboard.Dashboard" />
        <arg line=" -localWorkers 16" />
    </java>

    <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
        ........
        ........

        <arg value="com.af.gwtmodules.administration.Administration" />
        <arg line=" -localWorkers 16" />
    </java>

</parallel>
</target>

This indeed runs faster as expected. However, I wonder whether the GWT compiler can do a better job at code optimization if it is given all modules at once instead of each module separately. For example, the two modules use a lot of common code. So if the compiler can see the entire code base at once, it can find more redundant code. In theory, it can create a single JS artefact for the common code and separate JS artifacts for code that is not common. This would have the effect of reducing download time for the user who accesses both modules as common JS artifact would be downloaded only once.

As far as I understand GWT modules are independent and so there would be no cross module optimizations. But the fact that GWT compiler internally does not parallelize this makes me think that there could be some cross module optimizations or other ramifications because of which Google engineers decided against parallelizing it beyond a limit.

I would like to know if parallelizing compile the way I have done, has any effect on quality of generated code.

Upvotes: 0

Views: 1723

Answers (1)

Andrei Volgin
Andrei Volgin

Reputation: 41089

If your CPU runs at 100% or you use all of available memory, it does not matter how many tasks you run in parallel. In fact, you may slow down the performance, not improve it, by pushing tasks in parallel.

You already set localWorkers to 16. That's a lot of parallel threads. By passing two tasks you simply double the number of threads. If you get any performance improvement from increasing this number - go for it, although your results look surprising (either your app is very small or your computer is a monster).

There are no optimization benefits from compiling modules sequentially vs in parallel, as far as I know. You can always verify it by looking the at the size of the compiled code.

You may find this post interesting:

GWT Compilation Performance

Upvotes: 1

Related Questions