15

In my Scala/SBT project, I have one file that takes up to 5(!) minutes to compile. All the other ones can compile in a few seconds. This makes development pretty painful.

I'm sure that I'm abusing some Scala constructs, but I have no idea how to go about debugging it. How does one debug long compile times in Scala?

I'm using Scala 2.9.2 and SBT 0.11.2

Eyal
  • 317
  • 2
  • 7
  • 2
    Long compile times can have many reasons. Without posting the code, I doubt that you will get much help. A first step might be to split the file into several ones and see which parts take longest to compile. That also helps with _re_compilation times. – Kim Stebel Oct 16 '12 at 18:28
  • 1
    I can't break up the file without refactoring a lot of code, since it only contains one class. I'm more interested in seeing if there is some flag I can turn on in the compiler that can give me more hints as to where the problem is. – Eyal Oct 16 '12 at 18:54
  • 1
    Fair enough, but you can split the class into traits without touching the rest of the code. – Kim Stebel Oct 16 '12 at 19:01

1 Answers1

22

You can try the following Scala compiler options:

  • -Ystatistics Print compiler statistics

Find a phase that takes the most time. Then, try those:

  • -Xprint:<phase> Print out program after or "all"
  • -Yshow-trees Show detailed trees when used in connection with -print:phase
  • -Ydebug Output debugging messages
  • -Ypmat-debug Trace all pattern matcher activity.

To enable these settings directly from the sbt console, you can use set scalacOptions in ThisBuild += "-Ystatistics", or for more than one, set scalacOptions in ThisBuild ++= Seq("-Yshow-trees", "-Ydebug")

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
nau
  • 1,145
  • 8
  • 20