Skip to content

Allow continuations to have no ExecutionContext#128323

Open
jakobbotsch wants to merge 1 commit into
dotnet:mainfrom
jakobbotsch:optional-execution-context
Open

Allow continuations to have no ExecutionContext#128323
jakobbotsch wants to merge 1 commit into
dotnet:mainfrom
jakobbotsch:optional-execution-context

Conversation

@jakobbotsch
Copy link
Copy Markdown
Member

@jakobbotsch jakobbotsch commented May 18, 2026

ValueTaskContinuation does not need to save/restore ExecutionContext, and also in the future we expect to allow continuations to skip this save/restore when the JIT proved that it is not going to be looked at.

`ValueTaskContinuation` does not need to save/restore ExecutionContext,
and also in the future we expect to allow continuations to skip this
restoration when the JIT proved that it is not going to be looked at.
Copilot AI review requested due to automatic review settings May 18, 2026 12:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the CoreCLR runtime-async continuation machinery to support continuations that do not carry an ExecutionContext slot, and applies that to the hand-rolled ValueTaskContinuation so it no longer captures/restores ExecutionContext.

Changes:

  • Removed ExecutionContext storage/initialization from ValueTaskContinuation.
  • Replaced GetExecutionContext() with TryGetExecutionContext(out ...) and made dispatch restore conditional on an encoded EC slot being present.
  • Stopped capturing ExecutionContext when constructing ValueTaskContinuation for TransparentAwaitValueTask{OfT}.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.ValueTaskContinuation.cs Removes the ExecutionContext field and related flag encoding/clearing from the hand-rolled ValueTask continuation.
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs Adds TryGetExecutionContext and updates continuation dispatch to restore EC only when the continuation encodes an EC slot; removes EC capture for ValueTask continuation setup.

@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-threading-tasks
See info in area-owners.md if you want to be subscribed.

@jakobbotsch
Copy link
Copy Markdown
Member Author

PTAL @VSadov

@jakobbotsch jakobbotsch requested a review from VSadov May 18, 2026 16:10
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