I have been using Scala for the last two months. I am also using the Play Framework for a small app. I have observed that compilation is very slow even for a program to print \"
How fast is compilation in your case?
scalac's speed is bounded by two factors:
It's a rather large program that runs on the JVM. So startup times are not great because one has to (1) start the JVM (2) load scalac into it (3) JIT compile much of it to gain speed. Startup times of 2-4 seconds are typical, and the first couple runs of scalac are not super fast. If your setup is correct this will be mitigated by scalac being kept resident and "warm" in a running JVM. sbt does that, as do all IDEs. I recommend to use one of these options, or else, if you must compile from the command line, use "fsc" which also keeps the compiler resident. (Case in point: people generally do not complain about the speed of the REPL, yet the REPL uses the same scalac as everybody else. The difference is just that the compiler is kept resident).
Even a fully warmed-up scalac has to contend with programs that sometimes require complex type inference. So it cannot be as fast as compilers for languages with very simple type systems such as Go. I see on my 3 year old Macbook Pro compile speeds of 500-800 lines / second. This beats no world record, but it is sufficient for incremental compilation which is what IDEs and sbt do now. My current project is about 50K lines of code but I basically never wait for the compiler in my IDE (Scala IDE for Eclipse) because incremental compilation is fast enough. Some people see compile speeds that are lower than that. That's usually because they use constructs (often imported from a library) that are very expensive to compile, such as complicated implicit parameter hierarchies.
Well, this is kind of a duplicate question, but since it contains another, more practical part, I'll try to give an answer nevertheless.
First things first: compilation is slow because the language is rich with features. Of course, there are examples where languages with approximately the same set of features compile faster, but we have what we have. First few things that come to my mind are:
For a much more elaborate answer I refer you to Scala's creator Dr. Odersky himself:.
As for the second part of your question, that depends on how you compile:
scalac
, you can't achieve greater speed since you are bound to separete launches over and over.sbt
, the built-in incremental compiler (server) comes to your service: http://www.scala-sbt.org/0.13.5/docs/Detailed-Topics/Understanding-incremental-recompilation.htmlsbt
), it uses sbt server
as well: https://www.typesafe.com/blog/typesafe-activator-130-released-contains-new-sbt-server-and-uiI think in your case sticking to Activator is the best choice since you already use Play. But remember that this is not a silver bullet: you still get a slow first-time compilation and subsequent runs' speed depends on how much changes you introduced to the code.
Ah, and there's also a hardware side to it. It goes without saying that a powerful CPU, enough RAM and a fast (preferably SSD) disk drive will certainly reduce compilation speed.