Cache continuation used for runtime async callable task thunks#128320
Open
jakobbotsch wants to merge 1 commit into
Open
Cache continuation used for runtime async callable task thunks#128320jakobbotsch wants to merge 1 commit into
jakobbotsch wants to merge 1 commit into
Conversation
Contributor
|
Tagging subscribers to this area: @agocke |
Contributor
There was a problem hiding this comment.
Pull request overview
Applies the cached-continuation optimization from PR #127973 to Task-returning runtime async callable thunks. Instead of allocating per suspension, the thunks now reuse a thread-cached TaskContinuation instance, mirroring the ValueTaskContinuation design. The thunk IL is also restructured to emit an explicit TailAwait() followed by a generic TransparentAwait<T> (or non-generic), eliminating the suspension point inside each thunk.
Changes:
- New
TaskContinuationtype (cached inRuntimeAsyncAwaitState.CachedTaskContinuation) replaces the rawTaskNotifierfield;TransparentAwaitand the newTransparentAwaitOfT<T>allocate-only-on-miss. - Thunk IL emit (both CoreCLR JIT-time and AOT-time stub generators) now selects
TransparentAwaitvs. instantiatedTransparentAwaitOfT<T>and prepends aTailAwaitcall, removing the suspension point from the thunk itself. HandleSuspendedupdated to drive completion viataskCont.Task.TryAddCompletionActioninstead of the oldTaskNotifierpath.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.TaskContinuation.cs | New TaskContinuation continuation class, mirroring ValueTaskContinuation (Initialize/GetResult/Resume). |
| src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs | Replaces TaskNotifier with TaskContinuation; adds generic TransparentAwaitOfT<T>; updates HandleSuspended. |
| src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj | Adds new TaskContinuation source file to CoreCLR CoreLib build. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj | Adds new TaskContinuation source file to NativeAOT CoreLib build. |
| src/coreclr/vm/corelib.h | Defines TRANSPARENT_AWAIT_OF_T method binding for the new generic helper. |
| src/coreclr/vm/asyncthunks.cpp | Emits TailAwait + TransparentAwait/TransparentAwaitOfT<T> in the task-returning thunk IL. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/AsyncThunks.cs | AOT stub generator mirrors the same emit changes for task thunks. |
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.
Apply a similar optimization as #127973 to task returning thunks.
This is a very minor throughput optimization, but it also removes the suspension point from all these thunks, which makes each of these thunks smaller.
NAOT sizes