Skip to content

Check the IValueTaskSource case first in HandleSuspended - #133076

Merged
jakobbotsch merged 1 commit into
dotnet:mainfrom
jakobbotsch:async-vts-first-in-handlesuspended
Sep 17, 2026
Merged

jakobbotsch merged 1 commit into
dotnet:mainfrom
jakobbotsch:async-vts-first-in-handlesuspended

Conversation

@jakobbotsch

Copy link
Copy Markdown
Member

The introducers of asynchrony in RuntimeAsyncStackState are mutually exclusive, so the order of the checks in
RuntimeAsyncTask.HandleSuspended only affects how quickly each kind of suspension is dispatched. High-performance sources of asynchrony are increasingly expected to be IValueTaskSource based rather than ICriticalNotifyCompletion based, so test the ValueTaskSourceContinuation case first and let the awaiter/notifier cases fall through behind it.

No behavioral change.

The introducers of asynchrony in RuntimeAsyncStackState are mutually
exclusive, so the order of the checks in
RuntimeAsyncTask<T>.HandleSuspended only affects how quickly each kind of
suspension is dispatched. High-performance sources of asynchrony are
increasingly expected to be IValueTaskSource based rather than
ICriticalNotifyCompletion based, so test the ValueTaskSourceContinuation
case first and let the awaiter/notifier cases fall through behind it.

No behavioral change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 2146252b-ee64-4e0f-8aac-b9baa38e1a7a
@azure-pipelines

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The change is a straightforward reordering of mutually-exclusive dispatch cases with no functional logic changes and no issues found in surrounding invariants.

Pull request overview

Reorders the suspension-dispatch checks in RuntimeAsyncTask<T>.HandleSuspended to prioritize the IValueTaskSource-backed continuation path (ValueTaskSourceContinuation) before the awaiter/notifier/task continuation paths, aiming to reduce dispatch latency for that case without changing semantics.

Changes:

  • Checks ValueTaskSourceContinuation first in HandleSuspended, moving the other continuation cases after it.
  • Keeps the existing dispatch behavior for awaiter, critical notifier, and task continuation cases unchanged aside from evaluation order.
File summaries
File Description
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs Reorders HandleSuspended’s mutually-exclusive suspension-kind checks to prioritize the IValueTaskSource continuation path.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

@jakobbotsch

Copy link
Copy Markdown
Member Author

PTAL @VSadov. Simple change to reorder the checks to put IValueTaskSource first, since we expect that to be the highest performance source of asynchrony.

@jakobbotsch
jakobbotsch requested a review from VSadov September 4, 2026 07:14

@VSadov VSadov 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.

This is just a reorder of mutually exclusive checks with more likely one to be first.

I am not sure this will be easily observable in the overall scenario, but it makes sense.

@jakobbotsch
jakobbotsch merged commit eff64fb into dotnet:main Sep 17, 2026
107 of 110 checks passed
@jakobbotsch
jakobbotsch deleted the async-vts-first-in-handlesuspended branch September 17, 2026 09:29
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 18, 2026
jtschuster pushed a commit to jtschuster/runtime that referenced this pull request Sep 18, 2026
The introducers of asynchrony in RuntimeAsyncStackState are mutually
exclusive, so the order of the checks in
RuntimeAsyncTask<T>.HandleSuspended only affects how quickly each kind
of suspension is dispatched. High-performance sources of asynchrony are
increasingly expected to be IValueTaskSource based rather than
ICriticalNotifyCompletion based, so test the ValueTaskSourceContinuation
case first and let the awaiter/notifier cases fall through behind it.

No behavioral change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants