Skip to content

Perf: Throttle parallel typechecks in Find All References - #20128

Open
xperiandri wants to merge 2 commits into
dotnet:mainfrom
xperiandri:fix-find-references-throttle
Open

Perf: Throttle parallel typechecks in Find All References#20128
xperiandri wants to merge 2 commits into
dotnet:mainfrom
xperiandri:fix-find-references-throttle

Conversation

@xperiandri

Copy link
Copy Markdown
Contributor

Fixes #20127

Problem

Project.FindFSharpReferencesAsync launched one CancellableTask per document in the project simultaneously via CancellableTask.whenAll, causing an unbounded number of parallel typechecks (one per document) at once during Find All References / Rename.

Fix

  • Added CancellableTask.whenAllThrottled maxDegreeOfParallelism in CancellableTasks.fs, using a SemaphoreSlim to cap concurrency while preserving cancellation semantics.
  • Applied it in Project.FindFSharpReferencesAsync (WorkspaceExtensions.fs), capping concurrency to max 1 Environment.ProcessorCount.

@xperiandri
xperiandri marked this pull request as ready for review August 3, 2026 19:32
@xperiandri
xperiandri requested a review from a team as a code owner August 3, 2026 19: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

@T-Gro T-Gro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI review (@expert-reviewer): no significant issues found. Please verify independently.

Reviewed the throttling implementation for correctness:

  • use semaphore combined with return! Task.WhenAll(tasks) correctly awaits within the use scope, avoiding the common SemaphoreSlim use-after-dispose pitfall (this would be a bug with return instead of return!).
  • semaphore.WaitAsync(ct) is placed before the try, so Release() runs only when a permit was actually acquired — no risk of over-release, and cancelled waiters correctly skip the release.
  • The expensive start ct task runs only after acquiring a permit, so concurrency is genuinely capped.
  • max 1 Environment.ProcessorCount guarantees a valid (>= 1) semaphore count.

Cancellation and exception-aggregation semantics match the existing whenAll. LGTM.

@github-project-automation github-project-automation Bot moved this from New to In Progress in F# Compiler and Tooling Aug 4, 2026
@T-Gro
T-Gro self-requested a review August 4, 2026 09:11
@T-Gro T-Gro added the AI-reviewed PR reviewed by AI review council label Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-reviewed PR reviewed by AI review council AI-Tooling-Check-Scanned-Clean Tooling check: diff analyzed, no interesting infrastructure files

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Perf: Throttle parallel typechecks in Find All References

2 participants