Perf: Throttle parallel typechecks in Find All References - #20128
Open
xperiandri wants to merge 4 commits into
Open
Perf: Throttle parallel typechecks in Find All References#20128xperiandri wants to merge 4 commits into
xperiandri wants to merge 4 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
xperiandri
force-pushed
the
fix-find-references-throttle
branch
from
August 5, 2026 00:26
149109e to
c5582ba
Compare
Contributor
❗ Release notes requiredYou can open this PR in browser to add release notes: open in github.dev
|
xperiandri
force-pushed
the
fix-find-references-throttle
branch
from
August 5, 2026 08:37
c5582ba to
a86b21f
Compare
T-Gro
reviewed
Aug 12, 2026
| } | ||
|
|
||
| let tasks = seq { for task in tasks do yield runThrottled task } | ||
| return! Task.WhenAll (tasks) |
Member
There was a problem hiding this comment.
Task.WhenAll starts these tasks before the builder checks cancellation. Cancellation can dispose the semaphore before Release(), which then throws ObjectDisposedException. Keep the semaphore alive until all started tasks complete.
Contributor
Author
There was a problem hiding this comment.
Fixed in the latest commit
xperiandri
force-pushed
the
fix-find-references-throttle
branch
6 times, most recently
from
August 13, 2026 02:58
3164857 to
b63942a
Compare
… in Find All References (dotnet#20127)
Refactored the `whenAllThrottled` function to use an array of background tasks, ensuring each acquires/releases the semaphore properly. Explicitly disposes the semaphore after all tasks complete using a continuation on `Task.WhenAll`. Simplified the XML doc comment. This replaces the previous sequence expression and `use` binding with more robust disposal logic.
xperiandri
force-pushed
the
fix-find-references-throttle
branch
from
August 13, 2026 20:53
b63942a to
7268a33
Compare
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.