Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the incremental compilation speed in Scala depend on the number of classes per file?

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?

like image 652
python dude Avatar asked Aug 27 '12 09:08

python dude


People also ask

How does incremental compilation work?

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.

Why is Scala compiler so slow?

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.

What is zinc compiler?

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.


1 Answers

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.

like image 102
Iulian Dragos Avatar answered Oct 06 '22 20:10

Iulian Dragos