Skip to content

Enable Roslyn compiler output caching in non-official builds - #133748

Merged
akoeplinger merged 3 commits into
dotnet:mainfrom
agocke:enable-roslyn-compiler-cache
Sep 18, 2026
Merged

akoeplinger merged 3 commits into
dotnet:mainfrom
agocke:enable-roslyn-compiler-cache

Conversation

@agocke

@agocke agocke commented Sep 11, 2026

Copy link
Copy Markdown
Member

Enable Roslyn's experimental compiler output cache in the Unix x64/arm64 non-official build legs that already use sccache.

The setup:

  • persists the compiler cache with Azure Pipelines Cache@2
  • allows rolling builds to seed caches that PR builds can restore
  • preserves Azure's cache security boundary so PR writes cannot affect caches consumed by main
  • disables SourceLink for these non-official builds because commit-specific SourceLink inputs invalidate compiler cache entries
  • uses the deterministic PathMap already produced by ContinuousIntegrationBuild
  • reports per-build hit/store statistics alongside sccache statistics

Official builds are unaffected and continue to produce SourceLink-enabled outputs without using this cache.

In a two-commit libs.tests experiment using a Roslyn build containing dotnet/roslyn#84916, globally disabling SourceLink produced 358 hits and one store across 359 compiler invocations. The cached build took 4m53s versus 6m32s with the cache disabled, a 25.25% reduction (1.338x speedup). With SourceLink enabled, only 13 invocations hit.

A local integration probe using ROSLYN_CACHE_PATH produced 41 stores on the first rebuild and 41 hits on the second rebuild.

The Roslyn compiler output cache remains experimental. Cache read or write failures fall back to normal compilation, and the outer cache key is versioned so its provisional format can be invalidated independently.

Note

This pull request description was generated with GitHub Copilot.

Configure the experimental Roslyn compiler output cache alongside sccache for non-official builds. Disable SourceLink for those builds, persist the cache through Azure Pipelines, and report per-build cache statistics.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ab967da8-759b-499d-a20d-d6d6c2cc355d
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved concerns remain around cache growth, diagnostics preservation, and complete statistics coverage.

Get a fresh assessment by requesting another Copilot review.

Review tier: Lite
Findings: 1 Medium severity

Open findings (1)
What changed in this PR

Enables experimental Roslyn compiler-output caching for non-official Unix builds using sccache.

Changes:

  • Adds Azure Pipelines cache setup and SourceLink disabling.
  • Integrates cache arguments into global builds.
  • Reports Roslyn cache statistics.
File Summary
eng/​pipelines/​coreclr/​templates/​setup-sccache.yml Integrates Roslyn cache setup.
eng/​pipelines/​coreclr/​templates/​setup-roslyn-cache.yml Restores, configures, and persists the compiler cache.
eng/​pipelines/​coreclr/​templates/​sccache-stats.yml Reports compiler cache statistics.
eng/​pipelines/​coreclr/​templates/​roslyn-cache-stats.yml Collects per-build cache statistics.
eng/​pipelines/​common/​global-build-job.yml Forwards cache-specific build arguments.

Comment thread eng/pipelines/coreclr/templates/setup-roslyn-cache.yml
@jkoritzinsky

Copy link
Copy Markdown
Member

Can we add a script to enable this cache (and sccache) locally? It would be great if we could get to a point where a new worktree from a known commit would pull cached artifacts and make the baseline build much shorter.

@agocke

agocke commented Sep 12, 2026

Copy link
Copy Markdown
Member Author

Sccache just needs an environment variable set locally. Once this one is tested out I think it would make sense to have an opt-in as well. I want to try it out in CI first, though.

Comment thread eng/pipelines/coreclr/templates/setup-roslyn-cache.yml Outdated
@tannergooding

Copy link
Copy Markdown
Member

Last I checked sccache didn't really work on Windows, can we decouple this from that so that Windows can benefit from the Roslyn feature as well?

agocke and others added 2 commits September 16, 2026 23:20
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 501aac83-6191-40e5-8dc2-ef3acbcb1e41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The rolling cache grows without cleanup, and caching is unnecessarily enabled for a native-only job.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 3 Medium severity

Open (3)

Comment thread eng/pipelines/coreclr/templates/roslyn-cache-stats.yml
Comment thread eng/pipelines/coreclr/templates/setup-sccache.yml
@agocke

agocke commented Sep 17, 2026 •

Copy link
Copy Markdown
Member Author

I agree with decoupling from sccache but I want to enable incrementally, like I did with sccache. Let's start with Linux and go from there.

@agocke
agocke marked this pull request as ready for review September 17, 2026 14:58
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@agocke

agocke commented Sep 17, 2026

Copy link
Copy Markdown
Member Author

@akoeplinger Fixed. Anything else?

@agocke
agocke enabled auto-merge (squash) September 17, 2026 17:42
@akoeplinger
akoeplinger merged commit 501d63e into dotnet:main Sep 18, 2026
182 of 183 checks passed
@github-project-automation github-project-automation Bot moved this to Done in AppModel Sep 18, 2026
@agocke
agocke deleted the enable-roslyn-compiler-cache branch September 18, 2026 20:33
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants