Cache C# Compilation Emit by Project Version to avoid excessive background churn - #20119
Open
xperiandri wants to merge 3 commits into
Open
Cache C# Compilation Emit by Project Version to avoid excessive background churn#20119xperiandri wants to merge 3 commits into
xperiandri wants to merge 3 commits into
Conversation
- 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
Contributor
|
🔍 Tooling Safety Check — Affects-Build-Infra, Affects-Restore, Affects-Agent-Config, Scope-Review-Needed
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #20118.
Description
When C# projects change, Roslyn creates new
Compilationinstances. The F# IDE integration currently uses aConditionalWeakTableto cache the emitted PE reference from these compilations. Because newCompilationobjects 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>>toFSharpProjectOptionsManager.fs.This allows caching based on a stable identifier (
projectIdandproject.Version), avoiding unnecessary re-emission of assemblies when the underlying C# project hasn't functionally changed. The cache properly invalidates and handlesCancellationTokenviacancellableTask { ... }.