Allow continuations to have no ExecutionContext#128323
Open
jakobbotsch wants to merge 1 commit into
Open
Conversation
`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.
Contributor
There was a problem hiding this comment.
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
ExecutionContextstorage/initialization fromValueTaskContinuation. - Replaced
GetExecutionContext()withTryGetExecutionContext(out ...)and made dispatch restore conditional on an encoded EC slot being present. - Stopped capturing
ExecutionContextwhen constructingValueTaskContinuationforTransparentAwaitValueTask{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. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-threading-tasks |
This was referenced May 18, 2026
Member
Author
|
PTAL @VSadov |
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.
ValueTaskContinuationdoes 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.