Skip to content

very slow compiles on large ADT with pattern matches #14224

Open
@fommil

Description

@fommil

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.

Activity

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[/+] on Sep 20, 2023
fommil

fommil commented on Sep 20, 2023

@fommil
Author

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

changed the title [-]very slow compiles on large ADTs and/or lots of pattern matches[/-] [+]very slow compiles on large ADT with pattern matches[/+] on Sep 20, 2023
dwijnand

dwijnand commented on Sep 29, 2023

@dwijnand
Member

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @smarter@dwijnand@fommil

        Issue actions

          very slow compiles on large ADT with pattern matches · Issue #14224 · scala/scala3