Skip to content

Cache DocumentDiagnosticAnalyzer results by version stamp to avoid redundant typecheck on unchanged documents - #20121

Open
xperiandri wants to merge 1 commit into
dotnet:mainfrom
xperiandri:fix-document-diagnostic-analyzer-cache
Open

Cache DocumentDiagnosticAnalyzer results by version stamp to avoid redundant typecheck on unchanged documents#20121
xperiandri wants to merge 1 commit into
dotnet:mainfrom
xperiandri:fix-document-diagnostic-analyzer-cache

Conversation

@xperiandri

Copy link
Copy Markdown
Contributor

Fixes #20120

Summary

FSharpDocumentDiagnosticAnalyzer.GetDiagnostics previously recomputed syntax/semantic diagnostics (parse, typecheck, UnusedParentheses) on every crawler pass, even when the document text and project state had not changed since the last computation.

This adds a version-stamp-aware cache keyed by struct (DocumentId * DiagnosticsType), storing the last computed (textVersion, projectVersion, ImmutableArray<Diagnostic>) tuple:

  • For Syntax diagnostics, only the document textVersion is tracked (projectVersion uses VersionStamp.Default).
  • For Semantic diagnostics, both textVersion and document.Project.GetDependentVersionAsync() are tracked.
  • If the current versions match the cached entry, the cached diagnostics are returned directly, skipping parse/typecheck/UnnecessaryParenthesesDiagnosticAnalyzer work entirely.

This mirrors the versioned-cache pattern used for referenced-project compilation emission in FSharpProjectOptionsManager.fs (emitCache).

Testing

  • dotnet build vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj -c Debug — succeeded.
  • Deployed to RoslynDev hive (Build.cmd -c Debug -deployExtensions) and validated with a CPU trace of devenv.exe.

…recomputing diagnostics when document/project version is unchanged
@xperiandri xperiandri changed the title Cache DocumentDiagnosticAnalyzer results by version stamp to avoid redundant typecheck on unchanged documents Cache DocumentDiagnosticAnalyzer results by version stamp to avoid redundant typecheck on unchanged documents Aug 3, 2026
@xperiandri
xperiandri marked this pull request as ready for review August 3, 2026 00:33
@xperiandri
xperiandri requested a review from a team as a code owner August 3, 2026 00:33
@github-actions github-actions Bot added the AI-Tooling-Check-Scanned-Clean Tooling check: diff analyzed, no interesting infrastructure files label Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-Tooling-Check-Scanned-Clean Tooling check: diff analyzed, no interesting infrastructure files

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

P1: DocumentDiagnosticAnalyzer repeats typecheck/diagnostics work on every crawler pass (no version-stamp cache)

1 participant