Avoid duplicate ValueTask checks in transparent awaits - #133023
Open
jakobbotsch wants to merge 1 commit into
Open
Avoid duplicate ValueTask checks in transparent awaits#133023jakobbotsch wants to merge 1 commit into
jakobbotsch wants to merge 1 commit into
Conversation
Classify ValueTask backing objects once in TransparentAwait and pass typed Task or IValueTaskSource instances to the suspend helpers. This mirrors the existing AsyncHelpers.Await implementation and removes repeated type checks and temporary ValueTask materialization from runtime-async tail awaits. This is about 2% RPS improvement on the TechEmpower Arm64 JSON benchmarks. That benchmark was spending a not insignificant time in `CastHelpers.IsInstanceOfType` invoked by the duplicated `is Task<T>` check that was inside AsyncHelpers.TransparentSuspend. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1d56f651-7596-4378-81ee-21221f3c746e
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
jakobbotsch
force-pushed
the
runtime-async-transparent-await
branch
from
September 1, 2026 14:49
6631be7 to
0d9e098
Compare
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Pull request overview
This PR refactors the CoreCLR AsyncHelpers.TransparentAwait path for ValueTask/ValueTask<T> to classify the backing object once (Task vs IValueTaskSource*) and then call the appropriate suspend helper with the already-typed backing object, avoiding repeated runtime type checks during transparent/tail awaits.
Changes:
- Changes
TransparentSuspend(ValueTask)/TransparentSuspend(ValueTask<T>)intoTransparentSuspend(IValueTaskSource, short)/TransparentSuspend(IValueTaskSource<T>, short)and keeps Task-backed transparent suspension on the existingTransparentSuspend(Task)/TransparentSuspend(Task<T>)helpers. - Updates
TransparentAwait(ValueTask)/TransparentAwait(ValueTask<T>)to directly branch ontask._objand invokeTaskAwaiter.ValidateEndorIValueTaskSource*.GetResultas appropriate without re-materializing/recursively re-checking theValueTask.
File summaries
| File | Description |
|---|---|
| src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs | Moves ValueTask backing-object classification into TransparentAwait and passes typed backing objects to suspend helpers to reduce duplicated checks on the hot transparent-await path. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-threading-tasks |
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.
Classify ValueTask backing objects once in TransparentAwait and pass typed Task or IValueTaskSource instances to the suspend helpers. This mirrors the existing AsyncHelpers.Await implementation and removes repeated type checks and temporary ValueTask materialization from runtime-async tail awaits.
This is about 2% RPS improvement on the TechEmpower Arm64 JSON benchmarks. That benchmark was spending a not insignificant time in
CastHelpers.IsInstanceOfClassinvoked by the duplicatedis Task<T>check that was inside AsyncHelpers.TransparentSuspend. The primary source of that comes fromSocketReceiver.WaitForDataAsync.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com