Vivek Dhayaal
Vivek Dhayaal

Reputation: 1

impact of large number of source code files on compilation performance

I've a set of related scala case classes in each file as below: eg.

case class Book(pages: Seq[Page]);
case class Page(paras: Seq[Para]);
case class Para(lines: Seq[Line]);
case class Line(words: Seq[String]);
...

I've about 100 such files with each file containing a group of related case classes. The problem I see with this is that, some files grow very big to the extent of 500-1000 lines of code. My IDE takes a long to time to compile such large files and hangs at times, while editing such files. When I raise a PR, Github is not happy to render such large files' diff by default.

So, I plan to split each case class into a separate file, sticking to the rule of "1-class per file". The side effect of this is that now there could 1000s of files as I've a lot of such case classes.

Here is the question: Does switching from "small number(few 100s) of big files" approach to a "large number(1000s) of small files" approach have a negative impact on compilation performance? Could the increase in the number of files cause scala compiler to take a considerably long time to read all these files and compile? OR Could the decrease in file line count due to "1-class per file" approach, help the compiler perform better? Could there be any runtime performance difference between these two approaches?

Upvotes: 0

Views: 79

Answers (1)

simpadjo
simpadjo

Reputation: 4017

I think you are confusing compiler performance with IDE performance. Try closing your IDE and compile the project from the command line using sbt/gradle/maven. I believe it will be reasonably fast. In scala compiler performance could be ruined by a combination of implicits and type inference. Few thousand lines of plain class declarations shouldn't be a problem no matter how you split it. So you should choose what works best for you tools. Or maybe rethink application design.

Runtime performance will not change at all.

Upvotes: 1

Related Questions