Tips & tricks to decrease compile time

Are there tricks and tips to decrease compile time using scalac & sbt .

On top of my head:

  1. Split big files into smaller ones.
  2. Split big projects into multiple modules.
  3. Don’t abuse implicits.
  4. Prefer semi-auto derivation over automatic one.
  5. Keep an sbt server warn and running.
1 Like

Avoid circular dependencies. While they are often legal in Scala, it’s easy to fall into a trap where every change forces you to recompile the whole program, so you don’t get the usual benefits of incremental recompilation.

(Incremental recompilation is critically important. A huge program will always take a fairly long time to compile the first time, but if you’ve structured it correctly, subsequent compiles will usually be pretty fast.)

The implication is that, in Scala as in almost every other language, maintaining a clear separation of interfaces vs implementations tends to be a huge win.


I remember Martin Odersky saying in a video that type inference is costly, and that adding type annotations can help. Although I’m not sure if it makes a big difference.