Add size/perf optimized FinishSuspension helpers for runtime async#126041
Draft
jakobbotsch wants to merge 5 commits intodotnet:mainfrom
Draft
Add size/perf optimized FinishSuspension helpers for runtime async#126041jakobbotsch wants to merge 5 commits intodotnet:mainfrom
jakobbotsch wants to merge 5 commits intodotnet:mainfrom
Conversation
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces two new AsyncHelpers runtime helpers that allow the JIT to finish async suspension context handling with a single call, reducing generated code size and improving performance by avoiding multiple calls / repeated Thread TLS access.
Changes:
- Add
AsyncHelpers.FinishSuspensionNoContinuationContext/FinishSuspensionWithContinuationContextand update the JIT async suspension lowering to use them when execution context capture is needed. - Plumb the new helper method handles through
CORINFO_ASYNC_INFOand CoreLib binder + jitinterface, and teach R2R/NativeAOT dependency scanning to reference the methods. - Add an
ExecutionContextinternal instance property to cheaply query flow-suppressed state from the helper.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs | Exposes flow-suppressed state via a new internal instance property for use by suspension helpers. |
| src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs | Adds the new FinishSuspension helper implementations used by JIT-generated suspension code. |
| src/coreclr/inc/corinfo.h | Extends CORINFO_ASYNC_INFO with two new helper method handles. |
| src/coreclr/vm/jitinterface.cpp | Populates the new helper handles for the JIT via CEEInfo::getAsyncInfo. |
| src/coreclr/vm/corelib.h | Adds CoreLib binder entries for the two new helper methods. |
| src/coreclr/jit/async.h | Declares new JIT helper routines to emit the consolidated suspension context handling call. |
| src/coreclr/jit/async.cpp | Implements the new suspension context handling emission path using the new helpers. |
| src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs | Updates managed CORINFO_ASYNC_INFO struct layout to match native. |
| src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | Supplies the new helper method handles in the managed JIT interface implementation. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs | Adds the new helper methods as necessary async references for R2R compilation. |
| src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs | Ensures async scanning records dependencies on the new helper methods. |
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs
Show resolved
Hide resolved
This was referenced Mar 25, 2026
Open
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.
This adds two helpers,
FinishSuspensionNoContinuationContextandFinishSuspensionWithContinuationContextcalled by the JIT from generated suspension code that does all the necessary context handling needed on suspension for most common cases. Previously the JIT was creating multiple calls to accomplish the context handling. This is both a size and perf win in the generated code; suspension heavy micro benchmark below shows an ~8% perf improvement.Micro benchmark with warmup
This improves performance by about 8%:
Codegen diff