javaperformancescalacompilation

Java compile speed vs Scala compile speed


I've been programming in Scala for a while and I like it but one thing I'm annoyed by is the time it takes to compile programs. It's seems like a small thing, but with Java I could make small changes to my program, click the run button in NetBeans, and boom, it's running, and over time compiling in Scala seems to consume a lot of time. I hear that with many large projects, a scripting language becomes very important because of the time compiling takes, a need that I didn't see arising when I was using Java.

But I'm coming from Java which as I understand it, is faster than any other compiled language, and is fast because of the reasons I switched to Scala (it's a very simple language).

Can I make Scala compile faster and will scalac ever be as fast as javac?


Solution

  • The Scala compiler is more sophisticated than Java's, providing type inference, implicit conversion, and a much more powerful type system. These features don't come for free, so I wouldn't expect scalac to ever be as fast as javac. This reflects a trade-off between the programmer doing the work and the compiler doing the work.

    That said, compile times have already improved noticeably going from Scala 2.7 to Scala 2.8, and I expect the improvements to continue now that the dust has settled on 2.8. This page documents some of the ongoing efforts and ideas to improve the performance of the Scala compiler.

    Martin Odersky provides much more detail in his answer.