Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make Scala compilation 26% faster #97

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

Open
wants to merge 5 commits into
base: lucid-master
Choose a base branch
from

Conversation

jadenPete
Copy link

This PR speeds up Scala compilation with this ruleset by ~26% across-the-board and substantially reduces the complexity of the ruleset by using the compiler bridge directly instead of Zinc. Note that all the goodies we get from Zinc and its analysis information are not exclusive to Zinc and are instead gotten by using the compiler bridge, which Zinc invokes under the hood. However, this PR does drop support for incremental compilation.

Please read the commit messages (especially the second commit description) for more information on the technical context surrounding this decision.

Jaden Peterson added 2 commits June 24, 2025 17:01
Basic benchmarking shows that we're incurring a ~49% overhead from using
Zinc instead of the Scala compiler directly. That is, we wrote a basic
worker that invokes the Scala 2 compiler programmatically via
`scala.tools.nsc.Main`, and found that it was ~49% faster
across-the-board.

This doesn't necessarily mean that we can speed up `ZincRunner` by 49%.
A lot of that time is spent in compilation phases
[added](https://github.com/scala/scala/blob/2.13.x/src/sbt-bridge/scala/tools/xsbt/CallbackGlobal.scala#L166)
by the compiler bridge (implementation of the compiler interface)
itself. There are three of these phases; they're responsible for:
1. Mapping generated `.class` files to sources
2. Analyzing depedendencies between code
3. Producing the analysis information outputted by Zinc

We rely on 2 and 3 for:
- Dependency checking
- Detecting main classes
- Test discovery

We only use 2 and 3, and although it's likely the phases could be
slimmed down to only extract the information we need, implementing them
ourselves would add a lot of complexity to `ZincRunner` and make it
less portable . There's also no guarantee
that we could do a better job.

What can be eliminated is all the overhead related to incremental
compilation. We haven't used incremental compilation for years and have
no intention of re-enabling it.

This commit isn't about ripping out Zinc entirely; we still use Zinc for
the following things:
- Classloading the compiler interface from the compiler classpath
- Implementations of various `xsbti.*` traits and interfaces
@jadenPete jadenPete requested a review from jjudd July 1, 2025 18:07
@jadenPete jadenPete force-pushed the jpeterson-zincrunner-performance-improvements branch from 9b381ac to 531e308 Compare July 1, 2025 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants