Anurag
Anurag

Reputation: 406

How is Scala faster than Java when both are compiled into `.class` file which is run by JVM only?

I have read at many places that Scala is 20% faster than Java. However, I couldn't find an explanation to this. I have quite a good experience with Java but never really worked on Scala and was doing some research on the language choice for my next project.
My idea was that once the program is compiled, the JVM doesn't care if it was written in Scala or Java. Please correct me if I'm wrong.

Edit: Is there any research that proves Scala compiler has better compile optimizations as compared to Java compiler?

P.S.: I am not talking about Compile time, I am talking about run-time only.

Upvotes: 1

Views: 2253

Answers (1)

Tim
Tim

Reputation: 27356

You are probably seeing discussion of this paper. This is the key sentence:

Scala concise notation and powerful language features allowed for the best optimization of code complexity

The key point is that the Scala performance was better because it was quicker to write a more optimised version of the algorithm, rather than because the compiler did a better job of optimisation.

Upvotes: 7

Related Questions