python dude
python dude

Reputation: 8358

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?

Upvotes: 16

Views: 340

Answers (1)

Iulian Dragos
Iulian Dragos

Reputation: 5712

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.

Upvotes: 14

Related Questions