Repository navigation
Closed
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIruntime-async
Milestone
Description
For
private static async Task Example()
{
// Task await
await Callee();
// Configured task await
await Callee().ConfigureAwait(false);
// Custom awaiter
await Task.Yield();
}
private static async Task Callee()
{
}The codegen of these suspensions look like the following, respectively:
G_M25551_IG11: ;; offset=0x00AE
mov rax, gword ptr [rbp+0x10]
mov rbx, rax
test rbx, rbx
je SHORT G_M25551_IG12
lea rcx, bword ptr [rcx+0x08]
mov rdx, rbx
call CORINFO_HELP_ASSIGN_REF
jmp SHORT G_M25551_IG13
;; size=26 bbWeight=0 PerfScore 0.00
G_M25551_IG12: ;; offset=0x00C8
mov rdx, 0x7FF7C599A340 ; Continuation_16_0_2
call [CORINFO_HELP_ALLOC_CONTINUATION]
mov rbx, rax
;; size=19 bbWeight=0 PerfScore 0.00
G_M25551_IG13: ;; offset=0x00DB
lea rcx, [reloc @RWD00]
mov qword ptr [rbx+0x10], rcx
mov qword ptr [rbx+0x18], 32
lea rcx, bword ptr [rbx+0x20]
lea rdx, bword ptr [rbx+0x18]
call [System.Runtime.CompilerServices.AsyncHelpers:CaptureContinuationContext(byref,byref)]
call [System.Runtime.CompilerServices.AsyncHelpers:CaptureExecutionContext():System.Threading.ExecutionContext]
lea rcx, bword ptr [rbx+0x28]
mov rdx, rax
call CORINFO_HELP_ASSIGN_REF
cmp gword ptr [rbp+0x10], 0
setne cl
movzx rcx, cl
mov rdx, gword ptr [rbp-0x10]
mov r8, gword ptr [rbp-0x18]
call [System.Runtime.CompilerServices.AsyncHelpers:RestoreContextsOnSuspension(bool,System.Threading.ExecutionContext,System.Threading.SynchronizationContext)]
mov rcx, rbx
;; size=79 bbWeight=0 PerfScore 0.00
G_M25551_IG14: ;; offset=0x012A
add rsp, 56
pop rbx
pop rbp
retG_M25551_IG15: ;; offset=0x0131
mov rax, gword ptr [rbp+0x10]
mov rbx, rax
test rbx, rbx
je SHORT G_M25551_IG16
lea rcx, bword ptr [rcx+0x08]
mov rdx, rbx
call CORINFO_HELP_ASSIGN_REF
jmp SHORT G_M25551_IG17
;; size=26 bbWeight=0 PerfScore 0.00
G_M25551_IG16: ;; offset=0x014B
mov rdx, 0x7FF7C599A340 ; Continuation_16_0_2
call [CORINFO_HELP_ALLOC_CONTINUATION]
mov rbx, rax
;; size=19 bbWeight=0 PerfScore 0.00
G_M25551_IG17: ;; offset=0x015E
lea rax, [reloc @RWD16]
mov qword ptr [rbx+0x10], rax
mov rax, 0x100000001
mov qword ptr [rbx+0x18], rax
call [System.Runtime.CompilerServices.AsyncHelpers:CaptureExecutionContext():System.Threading.ExecutionContext]
lea rcx, bword ptr [rbx+0x28]
mov rdx, rax
call CORINFO_HELP_ASSIGN_REF
cmp gword ptr [rbp+0x10], 0
setne cl
movzx rcx, cl
mov rdx, gword ptr [rbp-0x10]
mov r8, gword ptr [rbp-0x18]
call [System.Runtime.CompilerServices.AsyncHelpers:RestoreContextsOnSuspension(bool,System.Threading.ExecutionContext,System.Threading.SynchronizationContext)]
mov rcx, rbx
;; size=71 bbWeight=0 PerfScore 0.00
G_M25551_IG18: ;; offset=0x01A5
add rsp, 56
pop rbx
pop rbp
retG_M25551_IG19: ;; offset=0x01AC
mov rax, gword ptr [rbp+0x10]
mov rbx, rax
test rbx, rbx
je SHORT G_M25551_IG20
lea rcx, bword ptr [rcx+0x08]
mov rdx, rbx
call CORINFO_HELP_ASSIGN_REF
jmp SHORT G_M25551_IG21
;; size=26 bbWeight=0 PerfScore 0.00
G_M25551_IG20: ;; offset=0x01C6
mov rdx, 0x7FF7C599A340 ; Continuation_16_0_2
call [CORINFO_HELP_ALLOC_CONTINUATION]
mov rbx, rax
;; size=19 bbWeight=0 PerfScore 0.00
G_M25551_IG21: ;; offset=0x01D9
lea rax, [reloc @RWD32]
mov qword ptr [rbx+0x10], rax
mov rax, 0x200000000
mov qword ptr [rbx+0x18], rax
call [System.Runtime.CompilerServices.AsyncHelpers:CaptureExecutionContext():System.Threading.ExecutionContext]
lea rcx, bword ptr [rbx+0x28]
mov rdx, rax
call CORINFO_HELP_ASSIGN_REF
cmp gword ptr [rbp+0x10], 0
setne cl
movzx rcx, cl
mov rdx, gword ptr [rbp-0x10]
mov r8, gword ptr [rbp-0x18]
call [System.Runtime.CompilerServices.AsyncHelpers:RestoreContextsOnSuspension(bool,System.Threading.ExecutionContext,System.Threading.SynchronizationContext)]
mov rcx, rbx
;; size=71 bbWeight=0 PerfScore 0.00
G_M25551_IG22: ;; offset=0x0220
add rsp, 56
pop rbx
pop rbp
ret- We can share the code to allocate the continuation. That's JIT: Continuation allocation code can be shared #125688.
- We can share the epilogs. That's JIT: Share suspension epilogs in async transformation #125174
This issue is about sharing the context handling at the tail of suspensions:
- Currently we call
CaptureExecutionContextandRestoreContextsOnSuspensionfor all suspension types. We can combine these into one call; they both need to accessThread.CurrentThread, so this will save the access and a function call, and size. - Instead of only sharing epilogs we should also be able to share these capture calls for all suspension points.
In the future it is likely that we will start optimizing to remove the CaptureExecutionContext and RestoreContextsOnSuspension calls when we realize that these cannot have changed, and then this sharing optimization will need to change (or become smarter). But we do not have that optimization yet.
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIruntime-async
Activity
dotnet-policy-service commentedon Mar 17, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
jakobbotsch commentedon May 8, 2026
Fixed by #126041 and #126360.