How to speed up ant apply over a set of files?
I'm using the following Ant apply task to run php lint over a set of PHP source files.
<apply executable="php" failonerror="true">
<arg value="-l" />
<filelist refid="server.lib" />
<filelist refid="server.scripts" />
<fileset refid="client.lib" />
<fileset refid="shared.lib" />
</apply>
Based on Ant's output, it takes around 30 seconds.
The same task performed by Make is almost instantaneous.
Is there a way to speed up the ant task?
EDIT
I've tried adding spawn="true" to the apply section and it sped up dramatically. Aside from the loss of logging, is this a good solution?
EDIT 2
spawn=true doesn't play nice with 'failonerror=t开发者_如何学JAVArue' so spawn won't work.
EDIT 3
To answer Hakre's question in the comments, the filesets cover 66 files all together. I can paste the ant output if that would help.
EDIT 4
Would it be possible to write this same task as an exec task instead?
Assuming it's a CI related job, you can apply your lint on modified files :
<fileset dir="." includes="**/*.php">
<modified />
</fileset>
if your code base is huge, it would be surprising you modify many files at once (per commit).
You can also take the problem the other way around and prevent commits altogether if the script is not valid (pre-commit hooks, etc)
- try to set the parallel atttribute to true, see Ant Manual
- try to run Ant with JVM in server mode, set VM parameter "-server" via ANT_OPTS
EDIT
my attempt would have been something like =
<patternset id="php.sources">
<include name="**/*.php"/>
</patternset>
<apply executable="php" failonerror="true" error="phperr.check" parallel="true">
<arg value="-l" />
<fileset dir="lib">
<patternset refid="php.sources" />
</fileset>
<fileset dir="scripts">
<patternset refid="php.sources" />
</fileset>
<fileset dir="client">
<patternset refid="php.sources" />
</fileset>
<fileset dir="shared">
<patternset refid="php.sources" />
</fileset>
<fileset dir="tests">
<patternset refid="php.sources" />
</fileset>
</apply>
what errormessage do you get when using parallel="true" ?
The parallelization of tasks can be achieved at a higher level:
<target name="phplint">
<parallel threadcount="2">
<apply executable="php" failonerror="true">
<arg value="-l" />
<fileset dir="${basedir}">
<include name="**/Dir1/**.php" />
</fileset>
</apply>
<apply executable="php" failonerror="true">
<arg value="-l" />
<fileset dir="${basedir}">
<include name="**/Dir2/**.php" />
</fileset>
</apply>
</parallel>
</target>
As the task is I/O consuming, dividing it into more threads yields a good decrease in execution time.
精彩评论