dotnet / dotnet/fsharp

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

Open
#20,118 0 comments 2 reactions 0 assignees View on GitHub
Needs-Triage
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

### 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.

### Expected Behavior
We should add a cache based on a stable identifier, such as `(ProjectId, project.Version)`, to avoid re-emitting assemblies unnecessarily when the underlying C# project hasn't functionally changed.

### Actual Behavior
The IDE often experiences excessive background activity because it forces frequent PE emissions for the same actual logic state.

Contributor guide

Open the contributing guide

Research direction

Start by locating the F# IDE integration that uses the ConditionalWeakTable and trace its calls to Compilation.Emit(metadataOnly=true). Compare the cache key with the stable ProjectId and project.Version described in the issue. Done means unchanged C# project state no longer causes repeated metadata-only emissions, while changed versions still refresh the reference.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, fsharp
Domain
performance, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.