scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.84k stars 1.05k forks source link

very slow compiles on large ADT with pattern matches #14224

Open fommil opened 2 years ago

fommil commented 2 years ago

Compiler version

3.1.0

Minimized code

https://gitlab.com/fommil/shapely

(the code is generated and found in the src_managed folder after running this command)

sbt ++3.1.0 test

A previous version of one of the slower files would crash the JVM even with 8GB of RAM so I gave up and refactored the code to use .asInstanceOf instead of explicit pattern matching.

Expectation

This codebase compiles in seconds on Scala 2.13, but takes minutes in Scala 3. I would expect it to have competitive performance with Scala 2.

This code is mostly pattern matching and subtyping calculations. Although the implicit keyword appears a lot, there's not actually any implicit resolution happening here.

fommil commented 1 year ago

This is still happening on 3.3.1.

Here are the files that emit the (false) warnings, and the warnings, although it is unclear if they are responsible for the slow compilation time because I can't find a Scala 3 port of scalac-profiling. https://gist.github.com/fommil/a33fa371a1cbeecab33a2462690bec8a

dwijnand commented 1 year ago

I had a look at this, and the slowness is in typer, not in the match analysis, using -Ydetailed-stats (with the code enable change). I tried to understand that further, with more trackTime wraps, but the times weren't adding up logically. But it seems to be growing with the arity - i.e. CaseClass64 was the slowest class def to type, after 63, etc. I wonder whether it's some part of the case class desugaring that is expensive. For instance, the copy method has 64 type parameters, 64 term parameters and 64 default term arguments (and additionally those 64 default term argument getters also each have the 64 type parameters..).

I also looked at the false warning, and am dealing with that part in #18616.