Address runtime async TaskScheduler TODO#129161
Open
jakobbotsch wants to merge 1 commit into
Open
Conversation
Avoid an unnecessary allocation for the TaskScheduler case.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the non-default TaskScheduler await-continuation path so CoreCLR’s runtime async continuation code can schedule/invoke the continuation without allocating a TaskSchedulerAwaitTaskContinuation instance, while preserving the existing inline-vs-queue behavior.
Changes:
- Extracts the “inline or schedule onto non-default
TaskScheduler” logic intoTaskSchedulerAwaitTaskContinuation.RunOrScheduleAction(...). - Refactors
AwaitTaskContinuation.CreateTask(...)to aprotected statichelper that takes an explicitExecutionContext?argument. - Updates CoreCLR runtime async continuation sites to call the new helper directly (removing the prior TODO and per-continuation object allocation).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs | Adds RunOrScheduleAction helper and refactors task creation to avoid needing an instance for the TaskScheduler path. |
| src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeAsyncTaskContinuation.cs | Uses RunOrScheduleAction directly instead of allocating TaskSchedulerAwaitTaskContinuation. |
| src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs | Uses RunOrScheduleAction directly in the captured-TaskScheduler continuation follow-up path. |
| bool inlineIfPossible = allowInlining && | ||
| (TaskScheduler.InternalCurrent == scheduler || Thread.CurrentThread.IsThreadPoolThread); | ||
|
|
||
| // Create the continuation task task. If we're allowed to inline, try to do so. |
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.
Avoid an unnecessary allocation for the TaskScheduler case.