I have written my first medium-sized project in Scala, and I am now a little worried that the slow incremental compilation time inside Eclipse might have something to do with my tendency to put my classes in relatively few, big .scala
files.
My logic behind this is as follows: If I modify a small class inside a big .scala
file and hit save, the compiler might only see that the entire file was somehow modified, and is therefore forced to recompile everything that's in the file along with the dependent classes, instead of just the modified class and its dependent classes.
So here's the question: Does the average number of Scala classes that you put in a single file in any way affect recompilation speed? Or to put it this way: In terms of recompilation speed, are small .scala
files to be preferred over big ones, or is there really no difference?
In imperative programming and software development, incremental compilation takes only the changes of a known set of source files and updates any corresponding output files (in the compiler's target language, often bytecode) that may already exist from previous compilations.
scalac's speed is bounded by two factors: It's a rather large program that runs on the JVM. So startup times are not great because one has to (1) start the JVM (2) load scalac into it (3) JIT compile much of it to gain speed.
Zinc is the incremental compiler for Scala. Most Scala developers use it daily without noticing – it's embedded in key build tools like sbt, pants, CBT, IntelliJ, and Scala IDE. The incremental compiler has one goal: to make your compilation times faster without sacrificing correctness.
You are right: the unit of dependency tracking is a file. If you make changes to a single class, but your compilation unit has several classes, this will trigger the recompilation of all the files that depend on the other classes in the same file.
Edit:
Since 0.13.6 sbt uses a new name-hashing scheme by default. This allows to recompile only files that have at least some dependency on a modified name.
This is the way Sbt works on the command line, and Eclipse uses the incremental compiler in Sbt.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With