Skip to content

Add size/perf optimized FinishSuspension helpers for runtime async - #126041

Merged
jakobbotsch merged 10 commits into
dotnet:mainfrom
jakobbotsch:optimize-suspension-tail
Apr 28, 2026
Merged

jakobbotsch merged 10 commits into
dotnet:mainfrom
jakobbotsch:optimize-suspension-tail

Conversation

@jakobbotsch

@jakobbotsch jakobbotsch commented Mar 24, 2026 •

Copy link
Copy Markdown
Member

This adds two helpers, FinishSuspensionNoContinuationContext and FinishSuspensionWithContinuationContext called by the JIT from generated suspension code that does all the necessary context handling needed on suspension for most common cases. Previously the JIT was creating multiple calls to accomplish the context handling. This is both a size and perf win in the generated code; suspension heavy micro benchmark below shows an ~8% perf improvement.

Micro benchmark with warmup
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;

namespace AsyncMicro;

public class Program
{
    static void Main()
    {
        NullAwaiter na = new NullAwaiter();

        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 100; j++)
            {
                Task t = Foo(100, na);
                while (!t.IsCompleted)
                {
                    na.Continue();
                }
            }

            Thread.Sleep(100);
        }

        for (int i = 0; i < 5; i++)
        {
            Task t = Foo(10_000_000, na);
            while (!t.IsCompleted)
            {
                na.Continue();
            }
        }
    }

    static int s_value;
    static async Task Foo(int n, NullAwaiter na)
    {
        for (int i = 0; i < n; i++)
        {
            s_value += i;
        }

        Stopwatch timer = Stopwatch.StartNew();
        for (int i = 0; i < n; i++)
        {
            await na;
        }

        if (n > 100)
            Console.WriteLine("Took {0:F1} ms", timer.Elapsed.TotalMilliseconds);
    }

    private class NullAwaiter : ICriticalNotifyCompletion
    {
        public Action Continue;

        public NullAwaiter GetAwaiter() => this;

        public bool IsCompleted => false;

        public void GetResult()
        {
        }

        public void UnsafeOnCompleted(Action continuation)
        {
            Continue = continuation;
        }

        public void OnCompleted(Action continuation)
        {
            throw new NotImplementedException();
        }
    }
}

This improves performance by about 8%:

-Took 284.2 ms
-Took 286.2 ms
-Took 285.4 ms
-Took 286.6 ms
-Took 286.7 ms
+Took 264.6 ms
+Took 265.4 ms
+Took 266.3 ms
+Took 265.9 ms
+Took 265.6 ms
Codegen diff
@@ -24,7 +24,7 @@ G_M000_IG01:                ;; offset=0x0000
        vmovdqu  ymmword ptr [rbp-0x60], ymm4
        mov      gword ptr [rbp+0x10], rcx
        mov      gword ptr [rbp+0x20], r8
-       mov      ebx, edx
+       mov      esi, edx
  
 G_M000_IG02:                ;; offset=0x0030
        test     rcx, rcx
@@ -42,26 +42,26 @@ G_M000_IG03:                ;; offset=0x0067
        mov      rax, gword ptr [rax+0x10]
        mov      rdx, gword ptr [rax+0x08]
        mov      gword ptr [rbp-0x48], rdx
-       mov      rdx, gword ptr [rax+0x10]
-       mov      gword ptr [rbp-0x50], rdx
+       mov      r8, gword ptr [rax+0x10]
+       mov      gword ptr [rbp-0x50], r8
  
 G_M000_IG04:                ;; offset=0x007B
        xor      eax, eax
-       test     ebx, ebx
+       test     esi, esi
        jle      SHORT G_M000_IG07
  
 G_M000_IG05:                ;; offset=0x0081
-       mov      rdx, 0x7FFA7F47B048
+       mov      rdx, 0x7FFA7F46B048
        align    [0 bytes for IG06]
  
 G_M000_IG06:                ;; offset=0x008B
        add      dword ptr [rdx], eax
        inc      eax
-       cmp      eax, ebx
+       cmp      eax, esi
        jl       SHORT G_M000_IG06
  
 G_M000_IG07:                ;; offset=0x0093
-       mov      rcx, 0x7FFA7F684FF0
+       mov      rcx, 0x7FFA7F674FF0
        call     CORINFO_HELP_NEWSFAST
        mov      rdi, rax
        mov      gword ptr [rbp-0x68], rdi
@@ -76,48 +76,48 @@ G_M000_IG08:                ;; offset=0x00BD
        mov      rdi, gword ptr [rbp-0x68]
        mov      qword ptr [rdi+0x10], rax
        mov      byte  ptr [rdi+0x18], 1
-       cmp      dword ptr [(reloc 0x7ffadf4683e0)], 0
+       cmp      dword ptr [(reloc 0x7ffadf468460)], 0
        jne      SHORT G_M000_IG14
  
 G_M000_IG09:                ;; offset=0x00D8
        mov      rdi, gword ptr [rbp-0x68]
-       test     ebx, ebx
+       test     esi, esi
        jle      SHORT G_M000_IG13
  
 G_M000_IG10:                ;; offset=0x00E0
-       mov      rsi, gword ptr [rbp+0x20]
-       cmp      byte  ptr [rsi], sil
-       mov      r14d, ebx
+       mov      rbx, gword ptr [rbp+0x20]
+       cmp      byte  ptr [rbx], bl
+       mov      r14d, esi
  
-G_M000_IG11:                ;; offset=0x00EA
-       mov      r8, rsi
-       mov      rcx, 0x7FFA7F686100
+G_M000_IG11:                ;; offset=0x00E9
+       mov      r8, rbx
+       mov      rcx, 0x7FFA7F676100
        xor      rdx, rdx
        call     [System.Runtime.CompilerServices.AsyncHelpers:UnsafeAwaitAwaiter[System.__Canon](System.__Canon)]
        test     rcx, rcx
        jne      G_M000_IG22
  
-G_M000_IG12:                ;; offset=0x0108
+G_M000_IG12:                ;; offset=0x0107
        dec      r14d
        jne      SHORT G_M000_IG11
  
-G_M000_IG13:                ;; offset=0x010D
-       cmp      ebx, 100
+G_M000_IG13:                ;; offset=0x010C
+       cmp      esi, 100
        jle      G_M000_IG16
        jmp      SHORT G_M000_IG15
  
-G_M000_IG14:                ;; offset=0x0118
+G_M000_IG14:                ;; offset=0x0117
        call     CORINFO_HELP_POLL_GC
        jmp      SHORT G_M000_IG09
  
-G_M000_IG15:                ;; offset=0x011F
+G_M000_IG15:                ;; offset=0x011E
        mov      rcx, rdi
        call     [System.Diagnostics.Stopwatch:get_ElapsedTicks():long:this]
        vxorps   xmm6, xmm6, xmm6
        vcvtsi2sd xmm6, xmm6, rax
-       mov      rcx, 0x7FFA7F684FF0
+       mov      rcx, 0x7FFA7F674FF0
        call     [CORINFO_HELP_GET_NONGCSTATIC_BASE]
-       vmulsd   xmm0, xmm6, qword ptr [(reloc 0x7ffa7f47b070)]
+       vmulsd   xmm0, xmm6, qword ptr [(reloc 0x7ffa7f46b070)]
        vcmpordsd xmm1, xmm0, xmm0
        vandpd   xmm1, xmm1, xmm0
        mov      rcx, 0x7FFFFFFFFFFFFFFF
@@ -125,25 +125,25 @@ G_M000_IG15:                ;; offset=0x011F
        vucomisd xmm0, qword ptr [reloc @RWD00]
        cmovb    rcx, rax
        mov      qword ptr [rbp-0x58], rcx
-       mov      rcx, 0x7FFA7F565A80
+       mov      rcx, 0x7FFA7F555A80
        call     CORINFO_HELP_NEWSFAST
        mov      rbx, rax
        lea      rcx, [rbp-0x58]
        call     [System.TimeSpan:get_TotalMilliseconds():double:this]
        vmovsd   qword ptr [rbx+0x08], xmm0
        mov      rdx, rbx
-       mov      rcx, 0x1D0BA5B05B8
+       mov      rcx, 0x25A2E3605B8
        call     [System.Console:WriteLine(System.String,System.Object)]
        nop      
  
-G_M000_IG16:                ;; offset=0x01A6
+G_M000_IG16:                ;; offset=0x01A5
        cmp      gword ptr [rbp+0x10], 0
        je       SHORT G_M000_IG20
  
-G_M000_IG17:                ;; offset=0x01AD
+G_M000_IG17:                ;; offset=0x01AC
        xor      ecx, ecx
  
-G_M000_IG18:                ;; offset=0x01AF
+G_M000_IG18:                ;; offset=0x01AE
        vmovaps  xmm6, xmmword ptr [rsp+0x50]
        add      rsp, 104
        pop      rbx
@@ -154,12 +154,12 @@ G_M000_IG18:                ;; offset=0x01AF
        pop      rbp
        ret      
  
-G_M000_IG19:                ;; offset=0x01C2
+G_M000_IG19:                ;; offset=0x01C1
        mov      ecx, 2
        call     CORINFO_HELP_GETDYNAMIC_GCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED
        jmp      G_M000_IG03
  
-G_M000_IG20:                ;; offset=0x01D1
+G_M000_IG20:                ;; offset=0x01D0
        mov      ecx, 2
        call     CORINFO_HELP_GETDYNAMIC_GCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED
        mov      rbx, gword ptr [rax+0x10]
@@ -170,7 +170,7 @@ G_M000_IG20:                ;; offset=0x01D1
        mov      rdx, r8
        call     CORINFO_HELP_ASSIGN_REF
  
-G_M000_IG21:                ;; offset=0x01F5
+G_M000_IG21:                ;; offset=0x01F4
        mov      r8, gword ptr [rbx+0x08]
        mov      rdx, gword ptr [rbp-0x48]
        cmp      rdx, r8
@@ -179,7 +179,7 @@ G_M000_IG21:                ;; offset=0x01F5
        call     [System.Threading.ExecutionContext:RestoreChangedContextToThread(System.Threading.Thread,System.Threading.ExecutionContext,System.Threading.ExecutionContext)]
        jmp      SHORT G_M000_IG17
  
-G_M000_IG22:                ;; offset=0x020D
+G_M000_IG22:                ;; offset=0x020C
        mov      rax, rcx
        mov      rcx, gword ptr [rbp+0x10]
        mov      r15, rcx
@@ -190,38 +190,35 @@ G_M000_IG22:                ;; offset=0x020D
        call     CORINFO_HELP_ASSIGN_REF
        jmp      SHORT G_M000_IG24
  
-G_M000_IG23:                ;; offset=0x022A
+G_M000_IG23:                ;; offset=0x0229
        mov      rcx, rax
-       mov      rdx, 0x7FFA7F6CD660
+       mov      rdx, 0x7FFA7F6BD660
        call     [CORINFO_HELP_ALLOC_CONTINUATION]
        mov      r15, rax
        lea      rcx, bword ptr [r15+0x28]
-       mov      rdx, rsi
+       mov      rdx, rbx
        call     CORINFO_HELP_ASSIGN_REF
        lea      rcx, bword ptr [r15+0x30]
        mov      rdx, rdi
        call     CORINFO_HELP_ASSIGN_REF
-       mov      dword ptr [r15+0x38], ebx
+       mov      dword ptr [r15+0x38], esi
  
-G_M000_IG24:                ;; offset=0x025C
-       lea      rax, [reloc @RWD08]
-       mov      qword ptr [r15+0x10], rax
-       xor      eax, eax
-       mov      qword ptr [r15+0x18], rax
+G_M000_IG24:                ;; offset=0x025B
+       lea      rcx, [reloc @RWD08]
+       mov      qword ptr [r15+0x10], rcx
+       xor      ecx, ecx
+       mov      qword ptr [r15+0x18], rcx
        mov      dword ptr [r15+0x3C], r14d
-       call     [System.Runtime.CompilerServices.AsyncHelpers:CaptureExecutionContext():System.Threading.ExecutionContext]
        lea      rcx, bword ptr [r15+0x20]
-       mov      rdx, rax
-       call     CORINFO_HELP_ASSIGN_REF
        cmp      gword ptr [rbp+0x10], 0
-       setne    cl
-       movzx    rcx, cl
-       mov      rdx, gword ptr [rbp-0x48]
-       mov      r8, gword ptr [rbp-0x50]
-       call     [System.Runtime.CompilerServices.AsyncHelpers:RestoreContextsOnSuspension(bool,System.Threading.ExecutionContext,System.Threading.SynchronizationContext)]
+       setne    dl
+       movzx    rdx, dl
+       mov      r8, gword ptr [rbp-0x48]
+       mov      r9, gword ptr [rbp-0x50]
+       call     [System.Runtime.CompilerServices.AsyncHelpers:FinishSuspensionNoContinuationContext(byref,bool,System.Threading.ExecutionContext,System.Threading.SynchronizationContext)]
        mov      rcx, r15
  
-G_M000_IG25:                ;; offset=0x029F
+G_M000_IG25:                ;; offset=0x0290
        vmovaps  xmm6, xmmword ptr [rsp+0x50]
        add      rsp, 104
        pop      rbx
@@ -232,22 +229,22 @@ G_M000_IG25:                ;; offset=0x029F
        pop      rbp
        ret      
  
-G_M000_IG26:                ;; offset=0x02B2
+G_M000_IG26:                ;; offset=0x02A3
        mov      rcx, gword ptr [rbp+0x10]
        mov      rcx, gword ptr [rcx+0x20]
        call     [System.Runtime.CompilerServices.AsyncHelpers:RestoreExecutionContext(System.Threading.ExecutionContext)]
        mov      rcx, gword ptr [rbp+0x10]
-       mov      rsi, gword ptr [rcx+0x28]
+       mov      rbx, gword ptr [rcx+0x28]
        mov      rdi, gword ptr [rcx+0x30]
-       mov      ebx, dword ptr [rcx+0x38]
+       mov      esi, dword ptr [rcx+0x38]
        mov      r14d, dword ptr [rcx+0x3C]
        jmp      G_M000_IG12
  
-G_M000_IG27:                ;; offset=0x02D8
+G_M000_IG27:                ;; offset=0x02C9
        sub      rsp, 40
        vzeroupper 
  
-G_M000_IG28:                ;; offset=0x02DF
+G_M000_IG28:                ;; offset=0x02D0
        cmp      gword ptr [rbp+0x10], 0
        setne    cl
        movzx    rcx, cl
@@ -256,7 +253,7 @@ G_M000_IG28:                ;; offset=0x02DF
        call     [System.Runtime.CompilerServices.AsyncHelpers:RestoreContexts(bool,System.Threading.ExecutionContext,System.Threading.SynchronizationContext)]
        nop      
  
-G_M000_IG29:                ;; offset=0x02F9
+G_M000_IG29:                ;; offset=0x02EA
        add      rsp, 40
        ret      
  
@@ -264,4 +261,4 @@ RWD00  	dq	43E0000000000000h
 RWD08  	dq	(dynamicClass):IL_STUB_AsyncResume(System.Object,byref):System.Object
 	dq	G_M000_IG22 + 3
 
-; Total bytes of code 766
+; Total bytes of code 751
NativeAOT test size changes
BaseSize DiffSize Delta Percent Name
31,201,792 31,155,200 -46,592 -0.149% System.Net.Http.Functional.Tests.exe
16,594,432 16,573,440 -20,992 -0.127% System.Linq.AsyncEnumerable.Tests.exe
14,931,968 14,916,096 -15,872 -0.106% System.Xml.Linq.Streaming.Tests.exe
16,546,304 16,529,920 -16,384 -0.099% System.Xml.Linq.Events.Tests.exe
16,813,568 16,797,184 -16,384 -0.097% System.Xml.Linq.Misc.Tests.exe
16,701,952 16,686,080 -15,872 -0.095% System.Xml.Linq.Properties.Tests.exe
17,155,072 17,139,200 -15,872 -0.093% System.Xml.Linq.TreeManipulation.Tests.exe
17,095,168 17,079,296 -15,872 -0.093% System.Xml.Linq.xNodeBuilder.Tests.exe
17,038,336 17,022,464 -15,872 -0.093% System.Xml.Linq.xNodeReader.Tests.exe
20,082,688 20,066,816 -15,872 -0.079% System.Formats.Tar.Tests.exe
22,769,664 22,752,768 -16,896 -0.074% System.Net.Sockets.Tests.exe
10,068,992 10,061,824 -7,168 -0.071% System.IO.Compression.ZipFile.Tests.exe
20,292,608 20,278,272 -14,336 -0.071% System.Threading.Tasks.Dataflow.Tests.exe
19,614,208 19,600,384 -13,824 -0.070% System.IO.Compression.Tests.exe
20,030,464 20,016,640 -13,824 -0.069% System.Net.WebSockets.Client.Tests.exe
28,832,768 28,813,312 -19,456 -0.067% System.Net.Http.WinHttpHandler.Functional.Tests.exe
20,997,120 20,983,296 -13,824 -0.066% System.Net.Quic.Functional.Tests.exe
17,744,896 17,734,656 -10,240 -0.058% System.Threading.Tasks.Extensions.Tests.exe
9,732,096 9,726,464 -5,632 -0.058% System.Threading.RateLimiting.Tests.exe
19,072,512 19,061,760 -10,752 -0.056% System.Net.HttpListener.Tests.exe
13,251,584 13,244,416 -7,168 -0.054% System.IO.Packaging.Tests.exe
14,579,200 14,571,520 -7,680 -0.053% System.Net.WebClient.Tests.exe
12,855,296 12,848,640 -6,656 -0.052% System.Xml.Schema.Extensions.Tests.exe
21,728,256 21,716,992 -11,264 -0.052% System.IO.FileSystem.Tests.exe
33,202,176 33,184,768 -17,408 -0.052% System.Private.Xml.Tests.exe
13,876,224 13,869,056 -7,168 -0.052% Microsoft.Extensions.Configuration.Functional.Tests.exe
13,948,928 13,941,760 -7,168 -0.051% Microsoft.Extensions.Configuration.Xml.Tests.exe
18,459,648 18,450,432 -9,216 -0.050% System.Threading.Tasks.Parallel.Tests.exe
12,421,632 12,415,488 -6,144 -0.049% System.Xml.Linq.SDMSample.Tests.exe
21,104,640 21,094,400 -10,240 -0.049% System.Net.Requests.Tests.exe
15,086,080 15,078,912 -7,168 -0.048% System.Security.Cryptography.Cng.Tests.exe
17,582,592 17,574,400 -8,192 -0.047% MetricOuterLoop1.Tests.exe
27,917,312 27,904,512 -12,800 -0.046% System.Net.Security.Tests.exe
115,773,440 115,720,192 -53,248 -0.046% System.Text.Json.SourceGeneration.Roslyn4.4.Tests.exe
18,390,528 18,382,336 -8,192 -0.045% Microsoft.Extensions.Primitives.Tests.exe
10,280,448 10,275,840 -4,608 -0.045% System.Threading.Channels.Tests.exe
17,577,472 17,569,792 -7,680 -0.044% MetricOuterLoop.Tests.exe
18,784,256 18,776,064 -8,192 -0.044% Microsoft.Extensions.FileProviders.Physical.Tests.exe
17,439,744 17,432,064 -7,680 -0.044% System.Net.Ping.Functional.Tests.exe
15,108,608 15,101,952 -6,656 -0.044% System.Drawing.Primitives.Tests.exe
17,800,704 17,793,024 -7,680 -0.043% System.Formats.Tar.Manual.Tests.exe
17,974,784 17,967,104 -7,680 -0.043% System.Threading.ThreadPool.WindowsThreadPool.Tests.exe
17,974,784 17,967,104 -7,680 -0.043% System.Threading.ThreadPool.Tests.exe
15,771,648 15,764,992 -6,656 -0.042% System.Windows.Extensions.Tests.exe
19,688,448 19,680,256 -8,192 -0.042% System.Net.Http.Unit.Tests.exe
17,161,728 17,154,560 -7,168 -0.042% IcuAppLocal.Tests.exe
18,501,120 18,493,440 -7,680 -0.042% Microsoft.Extensions.Configuration.Tests.exe
20,551,680 20,542,976 -8,704 -0.042% System.Threading.Tasks.Tests.exe
18,365,440 18,357,760 -7,680 -0.042% Microsoft.Extensions.FileProviders.Composite.Tests.exe
17,243,136 17,235,968 -7,168 -0.042% System.Runtime.InvariantTimezone.Tests.exe
17,295,872 17,288,704 -7,168 -0.041% System.Runtime.InteropServices.RuntimeInformation.Tests.exe
17,368,576 17,361,408 -7,168 -0.041% System.Diagnostics.StackTrace.Tests.exe
15,044,096 15,037,952 -6,144 -0.041% System.Data.DataSetExtensions.Tests.exe
17,319,424 17,312,256 -7,168 -0.041% System.Security.Principal.Windows.Tests.exe
17,623,552 17,616,384 -7,168 -0.041% System.Threading.Thread.Tests.exe
17,668,608 17,661,440 -7,168 -0.041% System.IO.FileSystem.Watcher.Tests.exe
17,337,344 17,330,176 -7,168 -0.041% System.Threading.Timer.Tests.exe
17,438,208 17,431,040 -7,168 -0.041% System.Diagnostics.TraceSource.Tests.exe
17,289,216 17,282,048 -7,168 -0.041% System.Threading.Overlapped.Tests.exe
14,134,784 14,129,152 -5,632 -0.040% System.DirectoryServices.Protocols.Tests.exe
19,299,328 19,291,648 -7,680 -0.040% System.IO.Pipes.Tests.exe
18,136,064 18,128,896 -7,168 -0.040% System.Diagnostics.TextWriterTraceListener.Tests.exe
18,593,280 18,586,112 -7,168 -0.039% ComInterfaceGenerator.Tests.exe
17,222,144 17,215,488 -6,656 -0.039% System.Net.ServicePoint.Tests.exe
18,525,184 18,518,016 -7,168 -0.039% System.IO.MemoryMappedFiles.Tests.exe
19,878,912 19,871,232 -7,680 -0.039% System.Text.Encoding.Tests.exe
18,496,000 18,488,832 -7,168 -0.039% Microsoft.Extensions.Hosting.Systemd.Tests.exe
19,555,328 19,547,648 -7,680 -0.039% System.Diagnostics.Process.Tests.exe
18,378,752 18,371,584 -7,168 -0.039% System.Threading.Tests.exe
17,167,360 17,160,704 -6,656 -0.039% System.Runtime.Serialization.Formatters.Disabled.Tests.exe
17,238,016 17,231,360 -6,656 -0.039% System.ComponentModel.EventBasedAsync.Tests.exe
18,184,704 18,177,536 -7,168 -0.039% System.Text.Encoding.CodePages.Tests.exe
18,462,720 18,455,552 -7,168 -0.039% Microsoft.Extensions.Configuration.FileExtensions.Tests.exe
24,296,448 24,287,232 -9,216 -0.038% Microsoft.Extensions.Http.Tests.exe
17,664,512 17,657,856 -6,656 -0.038% System.Buffers.Tests.exe
19,980,800 19,973,120 -7,680 -0.038% Microsoft.Extensions.Logging.Tests.exe
18,700,800 18,693,632 -7,168 -0.038% Microsoft.Extensions.Logging.Console.Tests.exe
27,176,448 27,166,208 -10,240 -0.038% Microsoft.Extensions.Hosting.Unit.Tests.exe
16,113,152 16,107,008 -6,144 -0.038% System.Data.Odbc.Tests.exe
17,305,600 17,298,944 -6,656 -0.038% System.Security.Claims.Tests.exe
17,362,944 17,356,288 -6,656 -0.038% Microsoft.Win32.SystemEvents.Tests.exe
20,484,096 20,476,416 -7,680 -0.037% System.Diagnostics.DiagnosticSource.Tests.exe
18,071,040 18,064,384 -6,656 -0.037% System.Console.Tests.exe
18,039,296 18,032,640 -6,656 -0.037% Microsoft.Extensions.Diagnostics.Tests.exe
20,539,392 20,531,712 -7,680 -0.037% System.Runtime.Extensions.Tests.exe
19,756,032 19,748,864 -7,168 -0.036% System.Resources.ResourceManager.Tests.exe
20,747,776 20,740,608 -7,168 -0.035% System.Collections.Concurrent.Tests.exe
19,087,360 19,080,704 -6,656 -0.035% Microsoft.Extensions.Hosting.WindowsServices.Tests.exe
10,103,808 10,100,224 -3,584 -0.035% Microsoft.Extensions.Caching.Memory.Tests.exe
20,241,408 20,234,240 -7,168 -0.035% System.Runtime.InteropServices.Tests.exe
20,461,056 20,453,888 -7,168 -0.035% System.Reflection.Tests.exe
18,841,600 18,834,944 -6,656 -0.035% System.Runtime.Caching.Tests.exe
19,491,328 19,484,672 -6,656 -0.034% Microsoft.Extensions.Configuration.UserSecrets.Tests.exe
19,302,912 19,296,256 -6,656 -0.034% System.Net.Primitives.Functional.Tests.exe
10,507,776 10,504,192 -3,584 -0.034% Microsoft.Extensions.Options.Tests.exe
21,629,440 21,622,272 -7,168 -0.033% System.Data.OleDb.Tests.exe
26,451,456 26,442,752 -8,704 -0.033% System.ComponentModel.TypeConverter.Tests.exe
9,439,232 9,436,160 -3,072 -0.033% Microsoft.Extensions.Logging.Testing.Tests.exe
9,249,280 9,246,208 -3,072 -0.033% Microsoft.Bcl.AsyncInterfaces.Tests.exe
9,656,832 9,653,760 -3,072 -0.032% Microsoft.Extensions.Hosting.Functional.Tests.exe
19,561,984 19,555,840 -6,144 -0.031% Microsoft.Extensions.Configuration.Json.Tests.exe
10,054,144 10,051,072 -3,072 -0.031% System.Net.ServerSentEvents.Tests.exe
11,585,024 11,581,440 -3,584 -0.031% System.Net.Http.Json.Unit.Tests.exe
23,411,712 23,404,544 -7,168 -0.031% System.Memory.Tests.exe
20,810,240 20,804,096 -6,144 -0.030% System.Security.Cryptography.Csp.Tests.exe
29,413,888 29,405,184 -8,704 -0.030% Microsoft.Extensions.DependencyModel.Tests.exe
25,900,544 25,892,864 -7,680 -0.030% System.Text.Json.SourceGeneration.Roslyn3.11.Tests.exe
21,079,552 21,073,408 -6,144 -0.029% Microsoft.Extensions.Logging.EventSource.Tests.exe
26,013,184 26,006,016 -7,168 -0.028% System.Globalization.Nls.Tests.exe
9,331,712 9,329,152 -2,560 -0.027% Microsoft.Extensions.Diagnostics.Abstractions.Tests.exe
11,273,216 11,270,144 -3,072 -0.027% System.IO.Compression.Brotli.Tests.exe
11,994,624 11,991,552 -3,072 -0.026% System.IO.Tests.exe
26,102,272 26,095,616 -6,656 -0.025% System.Globalization.Tests.exe
32,745,472 32,737,792 -7,680 -0.023% System.Linq.Expressions.Tests.exe
11,330,560 11,328,000 -2,560 -0.023% System.Net.WebSockets.Tests.exe
44,718,080 44,708,864 -9,216 -0.021% System.Runtime.Tests.exe
33,392,640 33,385,472 -7,168 -0.021% Microsoft.Bcl.Cryptography.Tests.exe
45,498,368 45,489,664 -8,704 -0.019% System.Security.Cryptography.Tests.exe
10,665,984 10,663,936 -2,048 -0.019% System.IO.Pipelines.Tests.exe
15,920,128 15,922,176 +2,048 +0.013% ilc.exe
8,927,232 8,926,208 -1,024 -0.011% Microsoft.Bcl.Memory.Tests.exe
10,485,248 10,484,224 -1,024 -0.010% System.Net.Http.WinHttpHandler.Unit.Tests.exe
13,417,472 13,418,496 +1,024 +0.008% crossgen2.exe
18,752,000 18,753,536 +1,536 +0.008% System.Numerics.Vectors.Tests.exe
8,615,424 8,614,912 -512 -0.006% System.Net.WebHeaderCollection.Tests.exe
8,576,000 8,575,488 -512 -0.006% Microsoft.Extensions.Hosting.Abstractions.Tests.exe
8,752,640 8,753,152 +512 +0.006% Microsoft.Bcl.TimeProvider.Tests.exe
8,637,952 8,637,440 -512 -0.006% Microsoft.Win32.Primitives.Tests.exe
8,691,712 8,691,200 -512 -0.006% System.Diagnostics.FileVersionInfo.Tests.exe
9,136,128 9,135,616 -512 -0.006% System.ComponentModel.Primitives.Tests.exe
8,964,608 8,964,096 -512 -0.006% System.Net.Primitives.Pal.Tests.exe
8,521,216 8,521,728 +512 +0.006% System.Runtime.CompilerServices.VisualC.Tests.exe
8,674,816 8,674,304 -512 -0.006% System.IO.FileSystem.Manual.Tests.exe
8,933,376 8,932,864 -512 -0.006% System.Threading.AccessControl.Tests.exe
9,181,184 9,180,672 -512 -0.006% Microsoft.Extensions.Configuration.EnvironmentVariables.Tests.exe
9,058,816 9,058,304 -512 -0.006% System.ValueTuple.Tests.exe
9,083,392 9,083,904 +512 +0.006% System.IO.FileSystem.AccessControl.Tests.exe
8,627,712 8,627,200 -512 -0.006% System.Globalization.CalendarsWithConfigSwitch.Tests.exe
10,574,336 10,573,824 -512 -0.005% Common.Tests.exe
9,737,728 9,737,216 -512 -0.005% System.Formats.Asn1.Tests.exe
9,325,056 9,325,568 +512 +0.005% System.IO.IsolatedStorage.Tests.exe
9,723,392 9,722,880 -512 -0.005% System.Collections.Specialized.Tests.exe
11,023,872 11,023,360 -512 -0.005% System.Runtime.Numerics.Tests.exe
9,561,088 9,560,576 -512 -0.005% System.Memory.Data.Tests.exe
10,037,760 10,037,248 -512 -0.005% System.Diagnostics.Debug.Tests.exe
9,621,504 9,620,992 -512 -0.005% System.Private.Uri.Functional.Tests.exe
11,767,808 11,768,320 +512 +0.004% System.Security.Cryptography.Cose.Tests.exe
12,174,848 12,174,336 -512 -0.004% System.Net.NetworkInformation.Functional.Tests.exe
11,582,976 11,582,464 -512 -0.004% System.Resources.Extensions.Tests.exe
15,374,336 15,373,824 -512 -0.003% System.Globalization.Extensions.Nls.Tests.exe
17,812,480 17,812,992 +512 +0.003% System.Collections.Tests.exe
9,189,888 9,189,888 0 0.000% System.ServiceProcess.ServiceController.Tests.exe
8,662,016 8,662,016 0 0.000% System.Runtime.InteropServices.ComDisabled.Tests.exe
108,032 108,032 0 0.000% CMakeCXXCompilerId.exe
8,644,096 8,644,096 0 0.000% System.Runtime.Handles.Tests.exe
84,480 84,480 0 0.000% System.Globalization.Native.dll
8,654,848 8,654,848 0 0.000% System.Runtime.CompilerServices.Unsafe.Tests.exe
1,377,280 1,377,280 0 0.000% System.IO.Compression.Native.dll
7,318,016 7,318,016 0 0.000% XUnitLogChecker.exe
108,032 108,032 0 0.000% CMakeCCompilerId.exe
1,935,296 1,935,296 0 0.000% Microsoft.DiaSymReader.Native.x86.dll
2,247,784 2,247,784 0 0.000% Microsoft.DiaSymReader.Native.arm64.dll
2,247,784 2,247,784 0 0.000% Microsoft.DiaSymReader.Native.arm64.dll
8,580,608 8,580,608 0 0.000% System.Resources.Writer.Tests.exe
9,335,296 9,335,296 0 0.000% System.Security.Permissions.Tests.exe
8,532,480 8,532,480 0 0.000% System.Text.Encoding.Extensions.Tests.exe
8,674,816 8,674,816 0 0.000% System.Security.Cryptography.ProtectedData.Tests.exe
11,167,232 11,167,232 0 0.000% System.Text.Encodings.Web.Tests.exe
22,308,864 22,308,864 0 0.000% System.Security.Cryptography.Pkcs.Tests.exe
9,678,848 9,678,848 0 0.000% System.Text.RegularExpressions.Unit.Tests.exe
8,791,552 8,791,552 0 0.000% System.Web.HttpUtility.Tests.exe
8,598,016 8,598,016 0 0.000% System.Xml.Linq.Axes.Tests.exe
2,309,152 2,309,152 0 0.000% Microsoft.DiaSymReader.Native.amd64.dll
1,754,512 1,754,512 0 0.000% Microsoft.DiaSymReader.Native.arm.dll
9,117,184 9,117,184 0 0.000% System.Security.AccessControl.Tests.exe
8,977,920 8,977,920 0 0.000% System.Runtime.Serialization.Primitives.Tests.exe
8,677,888 8,677,888 0 0.000% System.Security.SecureString.Tests.exe
1,935,296 1,935,296 0 0.000% Microsoft.DiaSymReader.Native.x86.dll
1,754,512 1,754,512 0 0.000% Microsoft.DiaSymReader.Native.arm.dll
10,934,272 10,934,272 0 0.000% System.Runtime.Intrinsics.Tests.exe
2,309,152 2,309,152 0 0.000% Microsoft.DiaSymReader.Native.amd64.dll
536,096 536,096 0 0.000% msquic.dll
8,517,632 8,517,632 0 0.000% System.IO.FileSystem.Primitives.Tests.exe
8,999,936 8,999,936 0 0.000% System.Reflection.TypeExtensions.Tests.exe
307,200 307,200 0 0.000% clretwrc.dll
678,400 678,400 0 0.000% clrgc.dll
722,944 722,944 0 0.000% clrgcexp.dll
4,956,160 4,956,160 0 0.000% coreclr.dll
210,944 210,944 0 0.000% corerun.exe
62,464 62,464 0 0.000% createdump.exe
1,935,296 1,935,296 0 0.000% Microsoft.DiaSymReader.Native.x86.dll
350,208 350,208 0 0.000% hostfxr.dll
1,502,720 1,502,720 0 0.000% mscordaccore_amd64_amd64_42.42.42.42424.dll
1,502,720 1,502,720 0 0.000% mscordaccore.dll
1,309,184 1,309,184 0 0.000% mscordbi.dll
536,096 536,096 0 0.000% msquic.dll
1,377,280 1,377,280 0 0.000% System.IO.Compression.Native.dll
16,982,016 16,982,016 0 0.000% System.Private.CoreLib.dll
361,984 361,984 0 0.000% hostpolicy.dll
2,309,152 2,309,152 0 0.000% Microsoft.DiaSymReader.Native.amd64.dll
2,247,784 2,247,784 0 0.000% Microsoft.DiaSymReader.Native.arm64.dll
1,754,512 1,754,512 0 0.000% Microsoft.DiaSymReader.Native.arm.dll
84,480 84,480 0 0.000% System.Globalization.Native.dll
1,377,280 1,377,280 0 0.000% System.IO.Compression.Native.dll
696,320 696,320 0 0.000% FileCheck.exe
9,956,352 9,956,352 0 0.000% llvm-mca.exe
7,703,040 7,703,040 0 0.000% ilasm.exe
8,732,160 8,732,160 0 0.000% Invariant.Tests.exe
9,936,896 9,936,896 0 0.000% LibraryImportGenerator.Tests.exe
8,566,784 8,566,784 0 0.000% Microsoft.Bcl.Numerics.Tests.exe
9,030,656 9,030,656 0 0.000% Microsoft.Extensions.Configuration.CommandLine.Tests.exe
9,462,784 9,462,784 0 0.000% Microsoft.Extensions.Configuration.Ini.Tests.exe
9,013,760 9,013,760 0 0.000% Microsoft.Extensions.FileSystemGlobbing.Tests.exe
2,309,152 2,309,152 0 0.000% Microsoft.DiaSymReader.Native.amd64.dll
1,754,512 1,754,512 0 0.000% Microsoft.DiaSymReader.Native.arm.dll
2,247,784 2,247,784 0 0.000% Microsoft.DiaSymReader.Native.arm64.dll
1,935,296 1,935,296 0 0.000% Microsoft.DiaSymReader.Native.x86.dll
2,309,152 2,309,152 0 0.000% Microsoft.DiaSymReader.Native.amd64.dll
1,754,512 1,754,512 0 0.000% Microsoft.DiaSymReader.Native.arm.dll
2,247,784 2,247,784 0 0.000% Microsoft.DiaSymReader.Native.arm64.dll
1,935,296 1,935,296 0 0.000% Microsoft.DiaSymReader.Native.x86.dll
696,320 696,320 0 0.000% FileCheck.exe
9,512,960 9,512,960 0 0.000% System.IO.Hashing.Tests.exe
8,903,680 8,903,680 0 0.000% System.IO.Pipes.AccessControl.Tests.exe
11,457,536 11,457,536 0 0.000% System.IO.Ports.Tests.exe
9,649,664 9,649,664 0 0.000% System.IO.UnmanagedMemoryStream.Tests.exe
15,199,744 15,199,744 0 0.000% System.Linq.Tests.exe
9,351,168 9,351,168 0 0.000% System.Net.Mail.Unit.Tests.exe
9,015,296 9,015,296 0 0.000% System.Net.NameResolution.Pal.Tests.exe
9,289,216 9,289,216 0 0.000% System.Net.Primitives.UnitTests.Tests.exe
11,351,040 11,351,040 0 0.000% System.Net.Security.Unit.Tests.exe
9,775,104 9,775,104 0 0.000% System.Net.WebProxy.Tests.exe
8,693,760 8,693,760 0 0.000% System.Private.Uri.Unit.Tests.exe
9,339,904 9,339,904 0 0.000% System.Reflection.Context.Tests.exe
8,838,144 8,838,144 0 0.000% System.Reflection.Extensions.Tests.exe
12,254,208 12,254,208 0 0.000% System.Reflection.Metadata.Tests.exe
8,743,936 8,743,936 0 0.000% System.IO.FileSystem.DriveInfo.Tests.exe
8,785,408 8,785,408 0 0.000% System.Resources.Reader.Tests.exe
15,374,336 15,374,336 0 0.000% System.Globalization.Extensions.Tests.exe
9,826,304 9,826,304 0 0.000% System.Formats.Nrbf.Tests.exe
1,754,512 1,754,512 0 0.000% Microsoft.DiaSymReader.Native.arm.dll
2,247,784 2,247,784 0 0.000% Microsoft.DiaSymReader.Native.arm64.dll
2,309,152 2,309,152 0 0.000% Microsoft.DiaSymReader.Native.amd64.dll
1,935,296 1,935,296 0 0.000% Microsoft.DiaSymReader.Native.x86.dll
8,621,056 8,621,056 0 0.000% Microsoft.Win32.Registry.AccessControl.Tests.exe
8,965,632 8,965,632 0 0.000% Microsoft.Win32.Registry.Tests.exe
9,923,072 9,923,072 0 0.000% System.Collections.NonGeneric.Tests.exe
8,522,240 8,522,240 0 0.000% System.ComponentModel.Tests.exe
8,532,992 8,532,992 0 0.000% System.Composition.AttributeModel.Tests.exe
9,605,120 9,605,120 0 0.000% System.Composition.Convention.Tests.exe
8,598,528 8,598,528 0 0.000% System.Composition.Runtime.Tests.exe
8,810,496 8,810,496 0 0.000% System.Console.Manual.Tests.exe
8,537,088 8,537,088 0 0.000% System.Diagnostics.Contracts.Tests.exe
9,600,512 9,600,512 0 0.000% System.Diagnostics.EventLog.Tests.exe
8,522,752 8,522,752 0 0.000% System.Diagnostics.Tools.Tests.exe
9,139,712 9,139,712 0 0.000% System.Globalization.Calendars.Tests.exe
9,956,352 9,956,352 0 0.000% llvm-mca.exe

Copilot AI review requested due to automatic review settings March 24, 2026 16:48
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 24, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces two new AsyncHelpers runtime helpers that allow the JIT to finish async suspension context handling with a single call, reducing generated code size and improving performance by avoiding multiple calls / repeated Thread TLS access.

Changes:

  • Add AsyncHelpers.FinishSuspensionNoContinuationContext / FinishSuspensionWithContinuationContext and update the JIT async suspension lowering to use them when execution context capture is needed.
  • Plumb the new helper method handles through CORINFO_ASYNC_INFO and CoreLib binder + jitinterface, and teach R2R/NativeAOT dependency scanning to reference the methods.
  • Add an ExecutionContext internal instance property to cheaply query flow-suppressed state from the helper.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs Exposes flow-suppressed state via a new internal instance property for use by suspension helpers.
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs Adds the new FinishSuspension helper implementations used by JIT-generated suspension code.
src/coreclr/inc/corinfo.h Extends CORINFO_ASYNC_INFO with two new helper method handles.
src/coreclr/vm/jitinterface.cpp Populates the new helper handles for the JIT via CEEInfo::getAsyncInfo.
src/coreclr/vm/corelib.h Adds CoreLib binder entries for the two new helper methods.
src/coreclr/jit/async.h Declares new JIT helper routines to emit the consolidated suspension context handling call.
src/coreclr/jit/async.cpp Implements the new suspension context handling emission path using the new helpers.
src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs Updates managed CORINFO_ASYNC_INFO struct layout to match native.
src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs Supplies the new helper method handles in the managed JIT interface implementation.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs Adds the new helper methods as necessary async references for R2R compilation.
src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs Ensures async scanning records dependencies on the new helper methods.

Copilot AI review requested due to automatic review settings March 24, 2026 17:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/inc/corinfo.h Resolved
Copilot AI review requested due to automatic review settings March 31, 2026 08:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/jit/async.cpp Resolved
Copilot AI review requested due to automatic review settings April 27, 2026 12:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings April 27, 2026 14:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.

@jakobbotsch

Copy link
Copy Markdown
Member Author

cc @dotnet/jit-contrib PTAL @EgorBo

@jakobbotsch
jakobbotsch requested a review from EgorBo April 27, 2026 21:22
Comment thread src/coreclr/jit/async.cpp Resolved
Comment thread src/coreclr/jit/async.cpp Resolved
@jakobbotsch
jakobbotsch merged commit 2e4f24b into dotnet:main Apr 28, 2026
175 checks passed
@jakobbotsch
jakobbotsch deleted the optimize-suspension-tail branch April 28, 2026 09:20
@github-actions github-actions Bot locked and limited conversation to collaborators May 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI runtime-async

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants