Try ClojureScript Parallel Compilation

November 14, 2015

Hah! It looks like David Nolen knocked off CLJS-957, landing experimental support for parallel ClojureScript compilation. It really amazes me how simple this changeset appears to be, relative to what I thought it might take. (Here it is.)




I've been especially interested in this ticket given that my main machine is an aging 2012 dual hexacore Mac Pro (lots of relatively slow cores compared the fewer faster cores you can get in a modern iMac). So, I immediately had to give this one a spin.

I tried the ClojureScript code for my iOS app as a test. But, since David's implementation appears to use all of the cores—(.. Runtime getRuntime availableProcessors) yields 24 on this box—I needed to add a few more source files to my project. I threw in DataScript, Garden, and a few other things, just to give it more stuff to compile in parallel.

The results look promising!

For a regular clean build in :none mode, it takes about 20 seconds (the code is on an SSD):

Successfully compiled "target/out/main.js" in 20.128 seconds. 

And, you can see that it is essentially single-threaded:


Now, let's flip the switch. This is done by simply adding the new :parallel-build true compiler option.

Now, for this project on this box, the build time is cut in half:

Successfully compiled "target/out/main.js" in 9.619 seconds.

And, the multiple cores are clearly more heavily utilized during compilation (those lower bars reflect hyper-threaded processors, and it's difficult to actually use them in practice, so this CPU snapshot is more impressive than it looks IMHO):


As an aside, being able to utilize multiple cores is one of the advantages of using the JVM-based compiler over a bootstrapped compiler toolchain.

As far as I can tell, using this experimental flag doesn't break anything. I tried smoke-testing my app and all is well. But, it is still new. Give it a try yourself and help ensure it is solid!

Tags: ClojureScript