scalac -optimise Compiles Are Slow | Mar 1, 2012

scalac, the Scala compiler, accepts an -optimise flag. I've heard anecdotally that it might sometimes improve runtime performance. I've personally never seen any hard data to indicate that it does very much (although it does have a very promising name.).

What I do know for sure, however, is that -optimise can make your compile times insanely slow. I've seen this affect a few friends, so I figured I'd mention it here to save any other wayward travelers.

Against an EC2 m1.small, compiling a roughly 3000 line Scala project (leaving out the tests), with Maven, and with Scala 2.9.1:

With -optimise:

[INFO] compile in 928 s
Without -optimise:
[INFO] compile in 47 s

There may have been something particularly awful about this one project that resulted in such an absurdly long compile time. But I've seen similarly bad numbers across a number of projects. At the very least, I've seen 10x increases in compile times while compiling on all sorts of machines.

Peter Hausel noted that there is ongoing work on improving speed for inlining, which seems like a step in the right direction. For now, avoid -optimise and keep your sanity while developing.