Skip to content

Slow Scala compilation times in 6.2.2 compared to 5.6.2 #12591

@SheliakLyr

Description

@SheliakLyr

Expected Behavior

I expected build times to stay the same or drop after upgrade to the newer version of Gradle. Small performance drop is also acceptable.

Current Behavior

For multimodule builds with Scala code build times increased dramatically (2 times the usual time). I've traced the problem to the tasks that compile Scala. I think this might be related to the Zinc upgrade.

Context

Fast compilation: Gradle 5.6.2
Slow compilation: Gradle 6.2.2, 6.3-rc4

I have two projects build with gradle (small one ~ 10 modules, large one ~ 100 modules). The problem occurs for both of them.

For small project:

Gradle 5.6.2:

gw clean compileScala --no-build-cache --profile

Two instances of GradleWorkerMain:
 - Non heap memory at the end: 180MB, 202MB
 - Loaded classes: 11274, 11047

Total time:
BUILD SUCCESSFUL in 2m 28s
61 actionable tasks: 60 executed, 1 up-to-date

Gradle 6.2.2:

gw clean compileScala --no-build-cache --profile

Two instances of GradleWorkerMain:
 - Non heap memory at the end: 714MB, 716MB
 - Loaded classes: 44244, 43294

Total time:
BUILD SUCCESSFUL in 4m 29s
61 actionable tasks: 60 executed, 1 up-to-date

I've profiled Gradle workers and have noticed a large increase in loaded classes and non-heap space usage. In 6.2.2 a lot of classes are loaded multiple times, for example:

  • scala.tools.nsc.Global (5 instances in different classloaders)

I've tried to build a single module and the times are the same in 5.6.2 and 6.2.2. Only multimodule builds are noticable slower.

Note: I'm not using the incremental Scala compilation:

        scalaCompileOptions.with {
            force = true
        }

Steps to Reproduce

I think this can be reproduced by any multimodule build with scala code.
Here is an example:
https://github.com/SheliakLyr/gradle-scala-slow-compilation-example

I tried to build it with 5.6.2 and 6.2.2: ./gradlew clean build --scan.
The build scan for 5.6.2: https://scans.gradle.com/s/dy5hsgpq3dotw
The build scan for 6.2.2: https://scans.gradle.com/s/ujdltbw6csltc

Task execution time for 5.6.2: 28s
Task execution time for 6.2.2: 6m+

Your Environment

https://scans.gradle.com/s/ujdltbw6csltc
I will be happy to answer any questions that might help you solve this issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions