Fast Flex Compilation With Maven: Israfil or Flex-mojos
In this post, I compare performance, measured in time taken to compile flex modules with maven, from two different maven flex plugins, israfil and flex-mojos.
The Contenders
If you compile flex projects from maven, you need a maven flex plugin. Targeting flex 3, there currently exists two plugins:
The Problem: Time Taken to Compile
One problem with the “mxmlc” compiler of the flex sdk is, that it is a Java program, which takes a fairly long time to execute. Of course, some of the compiler startup-time is JVM boostrap, but with JVMs of today, this time is negligible. What does take time is loading the classes of the flex compiler and initializing the compiler. A, rather small, flex application of mine, take 12-13 seconds to compile on a quad-core, linux-PC with 4Gb RAM and fast disks.
The Project Compiled
The project I am compiling in this test is a real-world application, with several flex modules. More precisely, the flex-modules of the project are:
- common: A library, swc, module, containing common as3 and ui code, all compiled into a flex library
- app1: A flex application, swf, which depends upon “common”, linking it into the application
- app2: Another flex application, swf, which depends upon “common”, linking it into the application
- shell: The last swf application, which acts as common entry point, that, when run, dynamically loads the other two apps on demand
The Contest: Timing Compiler Runs
Now for the really interesting part, the actual compilations and the time taken to do them with the two plugins of choice.
Compiling with Israfil
When compiling a maven module with flex code using the Israfil plugin, it simply spawns an “mxmlc” command line (the flex sdk command-line compiler) which then takes care of the compilation. When the plugin works like this, is means that you pay the penalty of mxmlc startup time for each module. Let us jump right into the numbers:
[INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] ------------------------------------------------------------------------ [INFO] client ............................................... SUCCESS [0.961s] [INFO] client-common ........................................ SUCCESS [8.085s] [INFO] client-app1 .......................................... SUCCESS [13.824s] [INFO] client-app2 .......................................... SUCCESS [9.972s] [INFO] client-shell ......................................... SUCCESS [11.655s] [INFO] ------------------------------------------------------------------------ [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 45 seconds [INFO] ------------------------------------------------------------------------
That is a whole 45 seconds, to compile all four maven modules!
With this maven run, I only pay maven startup time penalty once, and the reactor runs all the sub-modules as part of the one single “mvn” build command executed. Nevertheless, the build takes a long time, due to each module having israfil spawn an “mxmlc” process, to take care of compiling the flex code.
Compiling with Flex-mojos
The flex-mojos compiler works differently than the israfil plugin, in that the flex-mojos plugin does not spawn a new process at each compilation. Instead, it utilizes the flex3 oem compiler api, which is a programatic java api to the flex compiler. The same api that the mxmlc command-line compiler invokes after starting up. Given that compiler startup and warmup time is significant, this can lead to significanly faster builds, if more than one invocation of the compiler is done in the same “mvn” maven execution. And this exactly what happens, when you have more than one flex module in your project.
To the numbers:
[INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] ------------------------------------------------------------------------ [INFO] client ................................................ SUCCESS [1.744s] [INFO] client-common ......................................... SUCCESS [7.749s] [INFO] client-app1 ........................................... SUCCESS [8.126s] [INFO] client-app2 ........................................... SUCCESS [2.996s] [INFO] client-shell .......................................... SUCCESS [2.884s] [INFO] ------------------------------------------------------------------------ [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 24 seconds [INFO] Final Memory: 18M/163M [INFO] ------------------------------------------------------------------------
It takes “only” 24 seconds to compile with flex-mojos, which is roughly twice as fast as the 45 seconds of the israfil plugin.
This is certainly something to notice. It should be noted, that if you only have one module to compile, the two plugins will take roughly the same time to compile. On the other hand, as your project grows into more flex modules, flex-mojos will continue to cut down compile time significantly. Look at the numbers, and see how the two last modules takes only about 3 seconds to compile each. This is due to the flex compiler having warmed up and compiled both swc and swf modules before. Adding more modules will add only around 3 seconds each to the overall compile time.
In addition to the above numbers, flex-mojos have the ability to delegate flex compilation to an external compile server, the hellfire compiler, done by Clement Wong, a former Adobe employee it seems. This would enable fast builds for single modules also, with only the maven startup-time to pay as penalty. But that is something for another post.
Other Alternatives
One obvious alternative is using the Flex Builder IDE from Adobe for compilation. Flex builder use a compilation strategy similar to the one flex-mojos use, as in the compiler is kept warmed up and in memory. Actually, I would guess it to be the most efficient solution with respect to compile time, as it can keep the compiler warm over each execution. This is a consequence of flex builder being an IDE, which is running all the time, where the maven plugins are started up for each mvn execution. There are downsides to building with flex builder too, though:
- Needs IDE started, which rules out automatic integration builds, which has become an integral part of many development projects
- Forces developers into one build tool and IDE
- Costs money
- Is closed source
Of the above shown downsides, I find number 1 and 2 the most troublesome.
Another alternative is the flex compiler shell (fcsh), which I used a bit back in flex2. I did not ever feel comfortable using it, and noone have done any good, final, maven integration with it.


The flex-mojos project is really cool
Btw, I believe kicking ant or maven all the time to update the view layer is not the most productive process, so I started a free alternative plugin for eclipse. http://code.google.com/p/flexclipse/
July 15th, 2008 at 22:34[...] of the available plugins, that utilize the flex compiler api introduced in flex3, which makes for significantly faster builds than the other plugins, which simply acts as proxies for the mxmlc sdk command-line compiler. In [...]
July 15th, 2008 at 23:19I miss ANT on your contest.
VELO
July 16th, 2008 at 00:02I want to use Maven in my Flex project, but I think I’m either going to have to do my own plugin, or fork one of the existing ones, basically because in the opinions of the current project owners, my requirements “violate the Maven spirit”…ok, I don’t necessarily disagree, but they are my requirements and I must fulfill them in a manner that doesn’t drive me any more insane than I already am!
Basically I’ve got a main app frame, and then a bunch of individual UI elements, forms, whatever, that will all be bundled together in my WAR file. I have to load these dynamically from the server at run time, based on the user profile, and the only way I’ve seen so far to do that is to produce individual SWF’s for them. From what I’ve seen of the existing plugins though you might have multiple module inputs, your output is 1 swf or swc or rsl or what have you. Now personally, I’m producing 1 war, so I think I’m ok with the “1 artifact produced per project” philosophy.
July 17th, 2008 at 02:45So, I guess we’ll see.
Hi, Mike
From what you write, and I might misunderstand, I don’t see any problems using the existing plugins. I guess that it is with the maven rule about 1 artifact output pr. module, that you have problems?
What about a structure like the one I show above? You could have one flex source tree for each output artifact. Like, one for the framework, one for the uielements, and then bundle them in the war-file, which is a whole third source tree/module? If you need each UI element to be its own swf (?) you will of course end up with a lot of modules. If this scales badly for you, you could let the module/source-tree with the UI elements NOT build with a maven flex plugin, but simply use maven-antrun-plugin together with the adobe ant tasks to compile these to several artifacts. You will loose a bit of maven magic though, like installation of the artifacts into the repo after build etc.
Would any of that be helpful?
July 17th, 2008 at 08:29I am using the structure you suggest, I have each mxml in its own directory with any actionscript files, and it works fine with the ANTRUN and Flex ant tasks, I was just hoping I could make it more like my Java builds, dozens of classes compiled and put where I need them to be without any additional configuration, maybe just give it the output directory and my 80+ mxml’s would automagically be transformed into 80+ swfs in my designated directory.
July 17th, 2008 at 18:16Okay Mike, I can see you have some special needs there. 80+ swf artifacts are a lot.
July 17th, 2008 at 20:09Great post. Can you also provide the source code for reference.
September 26th, 2008 at 22:01Thanks
@Siva: Sorry, but no. The exact sources for the example above is closed, as in done for a client and something I cannot make public.
September 28th, 2008 at 08:51