Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

very slow compiles on large ADT with pattern matches #14224

Open
fommil opened this issue Jan 6, 2022 · 2 comments
Open

very slow compiles on large ADT with pattern matches #14224

fommil opened this issue Jan 6, 2022 · 2 comments
Labels

Comments

@fommil
Copy link

fommil commented Jan 6, 2022

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.

@dwijnand dwijnand added itype:bug stat:needs minimization Needs a self contained minimization and removed itype:bug labels Jan 10, 2022
@fommil fommil changed the title very slow compiles on large scala files with pattern matches very slow compiles on large ADTs and/or lots of pattern matches Sep 20, 2023
@fommil
Copy link
Author

fommil commented Sep 20, 2023

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

@fommil fommil changed the title very slow compiles on large ADTs and/or lots of pattern matches very slow compiles on large ADT with pattern matches Sep 20, 2023
@dwijnand
Copy link
Member

dwijnand commented Sep 29, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants