b-log – betriebsraum weblog

Software Development, Human-Computer Interaction, Projects…

Faster parallel MXMLC compilation using Ant

February 9, 2010

Whenever you have a Flex project consisting of several modules, you can take advantage of compiling those modules in parallel – provided that they don’t depend on each other – using Ant and the Ant-Contrib tasks. In a project with five modules, I’ve seen a speed increase of about 30% compared to normal sequential compilation. I haven’t tested yet how this setup performs with more modules but I guess you could run into memory problems when compiling too many of them in parallel (you could still compile them in batches then). Below is part of an Ant script which does the job…here a few notes:

Of course, you can also run this script on a CI-Server but if you want to use the IDE for parallel compilation: IntelliJ, for example, will support parallel compilation in the next update. Another way to speed things up is the HFCD compiler which I haven’t tried yet…

Here’s the Ant snippet (left out the property definitions):

<taskdef resource="net/sf/antcontrib/antlib.xml">
    <classpath>
        <pathelement location="libs/ant/ant-contrib-1.0b3.jar"/>
    </classpath>
</taskdef>
 
<fileset id="flex.source.files" dir="${flex.source.dir}">
    <include name="**/*.as"/>
    <include name="**/*.mxml"/>
    <include name="**/*.css"/>
</fileset>
 
<macrodef name="compile-app">
    <attribute name="debug" default="true"/>
    <attribute name="appName"/>
    <sequential>
        <outofdate>
            <sourcefiles>
                <fileset refid="flex.source.files"/>
            </sourcefiles>
            <targetfiles path="${flex.release.dir}/@{appName}.swf"/>
            <sequential>
                <java jar="${flex.sdk.dir}/lib/mxmlc.jar" fork="true" failonerror="true">
                    <arg value="-debug=@{debug}"/>
                    <arg value="-incremental=@{debug}"/>
                    <!-- rest of mxmlc options -->
                </java>
            </sequential>
        </outofdate>
    </sequential>
</macrodef>
 
<macrodef name="compile-all">
    <attribute name="debug" default="true"/>
    <sequential>
        <compile-app appName="main" debug="@{debug}"/>
        <for list="${flex.modules}" param="module.name" parallel="true">
            <sequential>
                <compile-app appName="@{module.name}" debug="@{debug}"/>
            </sequential>
        </for>
    </sequential>
</macrodef>
 
<target name="compile-all-debug">
    <compile-all debug="true"/>
</target>

Filed under: Flex/AS3, Software Development

Add a comment

You must be logged in to post a comment.