How can scalac's compilation speed improve?

It is said often that the compilation speed is slow about Scala. So I began to try improve compilation speed of scalac in my repository. I did to improve the compilation speed in my repository:

  • Replace many straightforward pattern matchings with pattern matchings compiled to tableswitch using @switch.
  • Cache hashCode
  • Replace many for-expressions with while expressions to avoid function object allocations.
  • , etc.

However, it doesn’t improve very much. Where is the bottleneck of scalac? I know typer phase takes much time. But I don’t know the detail.

using a @switch annotation doesn’t actually do anything, in the same way that using a @tailrec annotation doesn’t actually do anything, other than verifying that the the thing you expected to happen (emitting a switch, or eliminating the tailcall) actually happened.

A lot of effort has been put into this already, so if you want to help
you’d best sync up with the people that have worked on it already.
Hopefully they’ll reply here. You can also try the contributors gitter.
Meanwhile the assumption is that dotty will solve the problem when it takes
over. Also there has been some interesting work in finding parallelization

Jason and Lukas will focus on compiler performance at Lightbend this year. Currently, they’re working on benchmarking (see links below for work in progress). We have already done a lot of work a micro-optimisations and JVM-level profiling over the years. Our next steps will include looking below the VM level using tools like vtune etc. to understand cpu cache and memory access patterns. We’ll also look into adopting some of dotc’s ideas.

The projects at the links below are very much work in progress. By the end of Feb, we’ll make them more documented and accessible – we are very much looking for your help in writing more benchmarks, and making the compiler performance graph go up up up! :slight_smile: