Are there tricks and tips to decrease compile time using scalac & sbt .
On top of my head:
- Split big files into smaller ones.
- Split big projects into multiple modules.
- Don’t abuse implicits.
- Prefer semi-auto derivation over automatic one.
- Keep an sbt server warn and running.
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.