Skip to content

F# VS editor: reduce background CPU load by gating expensive analyzers to the active document only - #20117

Draft
xperiandri wants to merge 1 commit into
dotnet:mainfrom
xperiandri:fix/active-doc-gating
Draft

F# VS editor: reduce background CPU load by gating expensive analyzers to the active document only#20117
xperiandri wants to merge 1 commit into
dotnet:mainfrom
xperiandri:fix/active-doc-gating

Conversation

@xperiandri

Copy link
Copy Markdown
Contributor

Fixes #20114

Summary

CPU profiling of devenv.exe (VS Insiders + F# extension) showed ThreadPoolWorkQueue.Dispatch at 72 % total / 59 % self, driven by continuous F# background analysis running for all open tabs, not just the active one.

This PR implements the highest-impact P0 fixes from docs/ide/background-activity-minimization-plan.md:

Changes

New: ActiveDocumentDetection module

vsintegration/src/FSharp.Editor/Diagnostics/ActiveDocumentDetection.fs

Shared helper that uses IVsMonitorSelection / IVsWindowFrame to determine whether a Roslyn Document is the currently focused VS editor tab.

  • tryGetActiveDocumentMoniker — returns string voption (the active file path, or ValueNone)
  • isActiveDocument — returns bool; falls back to true (= don't suppress) when detection fails, so analysis is never silently lost

Gated analyzers / services

Component Before After
UnusedOpensDiagnosticAnalyzer Used inline shell detection Refactored to shared ActiveDocumentDetection module
UnusedDeclarationsAnalyzer No gating — ran full typecheck for every open tab Gated to active document
SimplifyNameDiagnosticAnalyzer No gating — 3 concurrent typechecks for all open tabs Gated to active document
FSharpInlayHintsService No gating — N−1 unnecessary typechecks Gated to active document

Behavior

  • Non-active documents receive no background diagnostics/hints while out of focus.
  • Switching to a tab immediately triggers fresh analysis for that tab.
  • This matches C#'s default behavior (BackgroundAnalysisScope.VisibleFilesAndOpenFilesWithPreviouslyReportedDiagnostics).
  • Roslyn clears stale diagnostics automatically when a document becomes active.

Not in scope (tracked in the plan)

- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

F# VS editor: reduce background CPU load by gating expensive analyzers to the active document only

1 participant