Uh oh!
There was an error while loading. Please reload this page.
Restore current task tracking for runtime async dispatch - #132969
Merged
max-charlamb merged 1 commit intoSep 1, 2026
Merged
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3514239f-5fe4-4f96-a3c8-0ef46470104e
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
Tagging subscribers to this area: @agocke |
MemberAuthor
@EgorBot -windows_amd -windows_intel --envvars DOTNET_TieredCompilation:0 usingSystem;usingSystem.Runtime.CompilerServices;usingSystem.Threading.Tasks;usingBenchmarkDotNet.Attributes;usingBenchmarkDotNet.Running;BenchmarkSwitcher.FromAssembly(typeof(DispatchContinuationsBenchmarks).Assembly).Run(args);publicclassDispatchContinuationsBenchmarks{privateconstintIterationCount=10_000_000;privatestaticints_value;privatereadonlyNullAwaiter_awaiter=new();[IterationSetup]publicvoidWarmup(){for(inti=0;i<IterationCount;i++){s_value+=i;}}[Benchmark(OperationsPerInvoke=IterationCount)]publicvoidDispatchContinuations(){Tasktask=RunContinuations(_awaiter);while(!task.IsCompleted){_awaiter.Continue();}task.GetAwaiter().GetResult();}[RuntimeAsyncMethodGeneration(true)]privatestaticasyncTaskRunContinuations(NullAwaiterawaiter){for(inti=0;i<IterationCount;i++){awaitawaiter;}}privatesealedclassNullAwaiter:ICriticalNotifyCompletion{privateAction?_continuation;publicNullAwaiterGetAwaiter()=>this;publicboolIsCompleted=>false;publicvoidContinue(){Actioncontinuation=_continuation!;_continuation=null;continuation();}publicvoidGetResult(){}publicvoidOnCompleted(Actioncontinuation)=>thrownewNotSupportedException();publicvoidUnsafeOnCompleted(Actioncontinuation)=>_continuation=continuation;}}namespaceSystem.Runtime.CompilerServices{[AttributeUsage(AttributeTargets.Method,Inherited=false,AllowMultiple=false)]internalsealedclassRuntimeAsyncMethodGenerationAttribute(boolruntimeAsync):Attribute{publicboolRuntimeAsync=>runtimeAsync;}} |
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
max-charlamb
requested review from
jakobbotsch, jkotas, lateralusX, rcj1 and tommcdonAugust 31, 2026 15:04
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
Pull request overview
Restores population of AsyncDispatcherInfo.CurrentTask during the standard (non-instrumented) runtime-async continuation dispatch path in CoreCLR, so diagnostic tooling can reliably correlate nested runtime-async tasks with their continuation chains.
Changes:
- Set
asyncDispatcherInfo.CurrentTask = this;in the non-instrumentedDispatchContinuationspath to match the intent of the instrumented path (which sets it viaRuntimeAsyncInstrumentationHelpers.ResumeRuntimeAsyncContext).
File summaries
| File | Description |
|---|---|
| src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs | Restores AsyncDispatcherInfo.CurrentTask assignment for standard continuation dispatch to enable correct current-task tracking during dispatch. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
jakobbotsch
approved these changes
Aug 31, 2026
rcj1
approved these changes
Aug 31, 2026
lateralusX
approved these changes
Sep 1, 2026
tommcdon
approved these changes
Sep 1, 2026
Uh oh!
There was an error while loading. Please reload this page.
max-charlamb
commented
Sep 1, 2026
MemberAuthor
/backport to release/11.0 |
Contributor
Started backporting to |
4 tasks
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 freeto 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.
Summary
AsyncDispatcherInfo.CurrentTaskon the standard, non-instrumentedDispatchContinuationspath.This assignment was present before the instrumented and non-instrumented dispatch paths were separated in #126091.
Reasoning
Without this link, diagnostics tools cannot deterministically find the parent Task for a runtime async continuation chain in non-instrumented scenarios like crash dumps. While it is possible to use heuristics to link the tasks (trying to find the 'this' parameter of the
DispatchContinuationscaller) these do not work in all scenarios.Given the very low overhead of writing this field, I believe it is valuable enough to re-add to the normal path.
Performance
Measured on Windows x64 under Hyper-V using BenchmarkDotNet with tiered compilation disabled. The benchmark performs 10,000 runtime-async suspensions and resumptions per invocation and compares separate baseline and changed Release testhosts.
Across 10 paired runs:
The changed runtime measured 1.83% faster overall. The eight additional runs measured 1.24% faster, with the changed runtime faster in all eight. Because the change adds a store and shifts generated code layout, the apparent improvement should be treated as layout or environmental noise rather than a causal speedup. No performance regression was detected.
ReadyToRun code size for
RuntimeAsyncTask<int>.DispatchContinuationsincreased by 7 bytes, from 1,488 to 1,495 bytes.Testing
System.Runtime.Tests: 77,810 total, 0 failed, 88 skippedNote
This pull request description was generated with GitHub Copilot.