views:

804

answers:

4

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).

So I wanted to ask, can I make Scala compile faster and will scalac ever be as fast as javac.

+4  A: 

Use fsc - it is a fast scala compiler that sits as a background task and does not need loading all the time. It can reuse previous compiler instance.

I'm not sure if Netbeans scala plugin supports fsc (documentation says so), but I couldn't make it work. Try nightly builds of the plugin.

tulskiy
The IntelliJ IDEA Scala plugin also has an option to use fsc
Aaron Novstrup
@anovstrup: yes, but it sometimes crashes.
tulskiy
+4  A: 

The latest revisions of Scala-IDE (Eclipse) are much better atmanaging incremental compilation.

See "What’s the best Scala build system?" for more.


The other solution is to integrate fsc - fast java compiler - (as illustrated in this blog post) as a builder in your IDE.

alt text

But not in directly Eclipse though, as Daniel Spiewak mentions in the comments:

You shouldn't be using FSC within Eclipse directly, if only because Eclipse is already using FSC under the surface.
FSC is basically a thin layer on top of the resident compiler which is precisely the mechanism used by Eclipse to compile Scala projects.


Finally, as Jackson Davis reminds me in the comments:

sbt (Simple build Tool) also include some kind of "incremental" compilation (through triggered execution), even though it is not perfect, and enhanced incremental compilation is in the work for the upcoming 0.9 sbt version.

VonC
sbt can also do incremental compiles
Jackson Davis
@Jackson: triggered execution, right! I have included it in my answer.
VonC
You shouldn't be using FSC within Eclipse directly, if only because Eclipse is *already* using FSC under the surface. FSC is basically a thin layer on top of the resident compiler which is *precisely* the mechanism used by Eclipse to compile Scala projects.
Daniel Spiewak
+14  A: 

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.

Aaron Novstrup
Isn't more this page (http://lamp.epfl.ch/~magarcia/ScalaCompilerCornerReloaded/)?
VonC
@VonC yes, thanks!
Aaron Novstrup
I've switched from netbeans to ant+jedit(I know I know, ant is for cavemen, but I'll evolve on my own time) so that I can use fsc. But I was wondering, how does the compile speed of Clojure compare to Scala? It seems to have many of the features in Scala but I imagine the syntax is much easier to parse.
We're kinda getting off-topic here, but Clojure's compiler is blisteringly fast (much faster than javac on equivalent sources). You're right that it's a really simple language though, and it doesn't have any sort of static type system, which helps quite a bit.
Daniel Spiewak
+4  A: 

I'm sure this will be down-voted, but extremely rapid turn-around is not always conducive to quality or productivity.

Take time to think more carefully and execute fewer development micro-cycles. Good Scala code is denser and more essential (i.e., free from incidental details and complexity). It demands more thought and that takes time (at least at first). You can progress well with fewer code / test / debug cycles that are individually a little longer and still improve your productivity and the quality of your work.

In short: Seek an optimum working pattern better suited to Scala.

Randall Schulz
@Randall, I agree that it's not essential to have a rapid turn-around cycle. But it doesn't hurt, does it?
Elazar Leibovich
I am not going to down-vote, but saying that you should adjust your working pattern to the limitations of your tool (the slow speed of the compiler) rather than trying to improve the tool is not a good argument. Especially the ability to do rapid test cycles is very valuable (even though it does not replace the need to do some deep thinking, the kind that is probably best done away from the keyboard, it does complement it nicely).
Thilo
I think most of my productivity is actually lost to over thinking before running. I frequently find myself looking at some equation for long periods trying to spot what ever potential pitfall is waiting for me, all while I'm thinking, "Just run it!" in the back of my head. And sure enough, when I run the program I learn a lot more than I probably would have with another hour or two of meditation. Meditation is good, but I feel I had a very optimal use of incremental compiling/meditation with java.
This is also similar to suggesting Shakespeare should not be using a spell-checker, and instead think harder about what he wants to say. The automated spell-checker helps with a completely different set of problems.
Thilo