Uh oh!
There was an error while loading. Please reload this page.
JIT: Enable implicit tailcalls for tail-awaits - #129255
Conversation
We disabled tailcalls from async methods when we added the context restore, but now that have and use tail-awaits we can reenable implicit tailcalls for those cases. That will also benefit async versions once that PR merges.
There was a problem hiding this comment.
Pull request overview
This change adjusts JIT tailcall eligibility for async methods: instead of blanket-disabling tailcalls from async methods, it allows implicit tailcalls only when the call is a tail await, while continuing to disqualify all other tailcall candidates from async methods.
Changes:
- Removed the early “caller is async method” tailcall disqualification.
- Added a late-stage tailcall eligibility check that permits tailcalls from async methods only for calls marked as async +
IsTailAwait.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jakobbotsch
commented
Jun 29, 2026
Uh oh!
There was an error while loading. Please reload this page.
We disabled tailcalls from async methods when we added the context
restore logic, but now that have and use tail-awaits we can reenable
implicit tailcalls for those cases.
Example:
```csharp
private static Task Foo(bool b)
{
return b ? Bar() : Baz();
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static async Task Bar()
{
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static async Task Baz()
{
}
```
```diff
G_M15357_IG01:
- sub rsp, 40
- ;; size=4 bbWeight=1 PerfScore 0.25
+ ;; size=0 bbWeight=1 PerfScore 0.00
G_M15357_IG02:
test dl, dl
- je SHORT G_M15357_IG04
+ je SHORT G_M15357_IG05
;; size=4 bbWeight=1 PerfScore 1.25
G_M15357_IG03:
xor rcx, rcx
- call [Program:Bar()]
- test rcx, rcx
- jne SHORT G_M15357_IG09
- jmp SHORT G_M15357_IG05
- ;; size=15 bbWeight=0.50 PerfScore 3.25
+ ;; size=2 bbWeight=0.50 PerfScore 0.12
G_M15357_IG04:
- xor rcx, rcx
- call [Program:Baz()]
- test rcx, rcx
- jne SHORT G_M15357_IG08
- ;; size=13 bbWeight=0.50 PerfScore 2.25
+ tail.jmp [Program:Bar()]
+ ;; size=6 bbWeight=0.50 PerfScore 1.00
G_M15357_IG05:
- xor ecx, ecx
- ;; size=2 bbWeight=1 PerfScore 0.25
+ xor rcx, rcx
+ ;; size=2 bbWeight=0.50 PerfScore 0.12
G_M15357_IG06:
- add rsp, 40
- ret - ;; size=5 bbWeight=1 PerfScore 1.25
-G_M15357_IG07:
- add rsp, 40
- ret - ;; size=5 bbWeight=0 PerfScore 0.00
-G_M15357_IG08:
- jmp SHORT G_M15357_IG07
- ;; size=2 bbWeight=0 PerfScore 0.00
-G_M15357_IG09:
- jmp SHORT G_M15357_IG07
- ;; size=2 bbWeight=0 PerfScore 0.00
+ tail.jmp [Program:Baz()]
+ ;; size=6 bbWeight=0.50 PerfScore 1.00
-; Total bytes of code 52, prolog size 4, PerfScore 8.50, instruction count 19, allocated bytes for code 52 (MethodHash=2415c402) for method Program:Foo(bool) (FullOpts)
+; Total bytes of code 20, prolog size 0, PerfScore 3.50, instruction count 6, allocated bytes for code 20 (MethodHash=2415c402) for method Program:Foo(bool) (FullOpts)
; ============================================================
```
We disabled tailcalls from async methods when we added the context restore logic, but now that have and use tail-awaits we can reenable implicit tailcalls for those cases.
Example: