Skip to content

-Wunused:all is slow to compile #19671

Closed
Closed
@oyvindberg

Description

@oyvindberg

Compiler version

3.4.0-RC4

Problem

First I want to celebrate the work that has been done for Scala 3.4 to provide Intellij with timing details so that you can see which phases are slow, which files cause much compilation time and so on. Great work!

So at $WORK we just migrated to Scala 3, and are facing slow compiles. Now I finally had the tools to dig a bit deeper. The first thing I found was that the two unused phases consume more time than typer for many of our sbt modules! I'll show an illustrative example here:

Screenshot 2024-02-12 at 00 11 59 Screenshot 2024-02-12 at 00 12 17

The data shown there seems to be correct, and can be reproduced with sbt.

Clean/compile for the same module with -Wunused:all enabled (slightly shorter times because of warmer compiler)

[success] Total time: 15 s, completed Feb 12, 2024, 12:15:43 AM
[success] Total time: 16 s, completed Feb 12, 2024, 12:16:11 AM
[success] Total time: 16 s, completed Feb 12, 2024, 12:16:11 AM

And without:

[success] Total time: 7 s, completed Feb 12, 2024, 12:18:44 AM
[success] Total time: 8 s, completed Feb 12, 2024, 12:18:58 AM
[success] Total time: 7 s, completed Feb 12, 2024, 12:19:11 AM

I'm also very happy that the unused functionality is back, and hope it can be optimized a bit. For now it's very easy to add all the flags from sbt-tpolecat, end up with a slow build and conclude that "Scala is slow to compile".

Reproducing

So this is a private project, but I suspect it will reproduce elsewhere. I tried for instance lichess lila (a prominent public scala 3 repo).

with unused:

[lila] $ user/clean;user/compile
[success] Total time: 0 s, completed Feb 12, 2024, 12:53:50 AM
[info] compiling 28 Scala sources and 1 Java source to /Users/oyvind/pr/lila/modules/user/target/scala-3.3.1/classes ...
[warn] -- Warning: /Users/oyvind/pr/lila/modules/user/src/main/Env.scala:5:35 ---------
[warn] 5 |import lila.common.autoconfig.{ *, given }
[warn]   |                                   ^^^^^
[warn]   |                                   unused import
[warn] -- Warning: /Users/oyvind/pr/lila/modules/user/src/main/Env.scala:10:19 --------
...
[warn] 9 warnings found
[success] Total time: 5 s, completed Feb 12, 2024, 12:53:56 AM
[lila] $ user/clean;user/compile

without unused:

[lila] $ user/clean;user/compile
[success] Total time: 0 s, completed Feb 12, 2024, 12:54:58 AM
[info] compiling 28 Scala sources and 1 Java source to /Users/oyvind/pr/lila/modules/user/target/scala-3.3.1/classes ...
[success] Total time: 3 s, completed Feb 12, 2024, 12:55:01 AM

I can also be of assistance with for instance profiling data if that helps.

Concurrent linting question

I assume compiler trees are immutable and linting phases don't affect the output trees. Did you look into running them in the background as the compiler progresses?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions