Perf: Throttle parallel typechecks in Find All References - #20128
Open
xperiandri wants to merge 2 commits into
Open
Perf: Throttle parallel typechecks in Find All References#20128xperiandri wants to merge 2 commits into
xperiandri wants to merge 2 commits into
Conversation
xperiandri
marked this pull request as ready for review
August 3, 2026 19:32
T-Gro
approved these changes
Aug 4, 2026
T-Gro
left a comment
Member
There was a problem hiding this comment.
🤖 AI review (@expert-reviewer): no significant issues found. Please verify independently.
Reviewed the throttling implementation for correctness:
use semaphorecombined withreturn! Task.WhenAll(tasks)correctly awaits within theusescope, avoiding the commonSemaphoreSlimuse-after-dispose pitfall (this would be a bug withreturninstead ofreturn!).semaphore.WaitAsync(ct)is placed before thetry, soRelease()runs only when a permit was actually acquired — no risk of over-release, and cancelled waiters correctly skip the release.- The expensive
start ct taskruns only after acquiring a permit, so concurrency is genuinely capped. max 1 Environment.ProcessorCountguarantees a valid (>= 1) semaphore count.
Cancellation and exception-aggregation semantics match the existing whenAll. LGTM.
T-Gro
self-requested a review
August 4, 2026 09:11
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 #20127
Problem
Project.FindFSharpReferencesAsynclaunched oneCancellableTaskper document in the project simultaneously viaCancellableTask.whenAll, causing an unbounded number of parallel typechecks (one per document) at once during Find All References / Rename.Fix
CancellableTask.whenAllThrottled maxDegreeOfParallelisminCancellableTasks.fs, using aSemaphoreSlimto cap concurrency while preserving cancellation semantics.Project.FindFSharpReferencesAsync(WorkspaceExtensions.fs), capping concurrency tomax 1 Environment.ProcessorCount.