Skip to content

Cache C# Compilation Emit by Project Version to avoid excessive background churn - #20119

Open
xperiandri wants to merge 3 commits into
dotnet:mainfrom
xperiandri:revert-20080-t-gro-net11-upgrade
Open

Cache C# Compilation Emit by Project Version to avoid excessive background churn#20119
xperiandri wants to merge 3 commits into
dotnet:mainfrom
xperiandri:revert-20080-t-gro-net11-upgrade

Conversation

@xperiandri

Copy link
Copy Markdown
Contributor

Fixes #20118.

Description

When C# projects change, Roslyn creates new Compilation instances. The F# IDE integration currently uses a ConditionalWeakTable to cache the emitted PE reference from these compilations. Because new Compilation objects are continually created by Roslyn, the weak table cache misses, causing repeated, expensive metadata-only emissions (Compilation.Emit(metadataOnly=true)). This contributes to UI latency and background CPU churn.

Solution

This PR adds an emitCache: ConcurrentDictionary<ProjectId, ConcurrentDictionary<VersionStamp, FSharpReferencedProject>> to FSharpProjectOptionsManager.fs.
This allows caching based on a stable identifier (projectId and project.Version), avoiding unnecessary re-emission of assemblies when the underlying C# project hasn't functionally changed. The cache properly invalidates and handles CancellationToken via cancellableTask { ... }.

abonie and others added 3 commits July 29, 2026 10:48
- Add ActiveDocumentDetection module (IVsMonitorSelection-based helper)
- Gate UnusedDeclarationsAnalyzer to active document
- Gate SimplifyNameDiagnosticAnalyzer to active document
- Gate FSharpInlayHintsService to active document
- Gate UnusedOpensDiagnosticAnalyzer to active document
- Add ActiveDocumentDetection.fs to FSharp.Editor.fsproj

Fixes dotnet#20114
@xperiandri
xperiandri requested a review from a team as a code owner August 2, 2026 22:45
@github-actions github-actions Bot added ⚠️ Affects-Agent-Config Tooling check: PR modifies AI agent instructions or workflows ⚠️ Affects-Build-Infra Tooling check: PR touches build infrastructure ⚠️ Affects-Restore Tooling check: PR touches NuGet packages or feeds ⚠️ Scope-Review-Needed Tooling check: PR scope exceeds title/description labels Aug 2, 2026
@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

🔍 Tooling Safety Check — Affects-Build-Infra, Affects-Restore, Affects-Agent-Config, Scope-Review-Needed
Affects-Build-Infra: modifies eng/common build scripts and props
Affects-Restore: changes eng/Versions.props and Version.Details.xml
Affects-Agent-Config: modifies .github/skills/pr-description/SKILL.md
Scope-Review-Needed: title claims "Cache C# Compilation Emit" but files are all eng/ infra

Generated by PR Tooling Safety Check · opus46 3.2M ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚠️ Affects-Agent-Config Tooling check: PR modifies AI agent instructions or workflows ⚠️ Affects-Build-Infra Tooling check: PR touches build infrastructure ⚠️ Affects-Restore Tooling check: PR touches NuGet packages or feeds ⚠️ Scope-Review-Needed Tooling check: PR scope exceeds title/description

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

[Ide] Excessive Compilation.Emit due to Roslyn Compilation churn for C# references

2 participants