From 2a602fdf874e745d849fa0eb4c07a7d4257c1e4c Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 21 Apr 2026 17:17:50 +0200 Subject: [PATCH 1/2] Mark Continuation field accessors as `AggressiveInlining` The intrinsic-heavy code appears big to the JIT, but in reality expands to just a handful of instructions. --- .../System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs index fb1d08b056eb89..a71224cf399943 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs @@ -111,6 +111,7 @@ internal unsafe class Continuation // See note in ContinuationFlags above for the computation of these offsets. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe object GetContinuationContext() { const uint mask = (1u << (int)ContinuationFlags.ContinuationContextIndexNumBits) - 1; @@ -120,6 +121,7 @@ public unsafe object GetContinuationContext() return Unsafe.As(ref Unsafe.Add(ref data, (DataOffset - PointerSize) + index * PointerSize)); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool HasException() { const uint mask = (1u << (int)ContinuationFlags.ExceptionIndexNumBits) - 1; @@ -135,6 +137,7 @@ public void SetException(Exception ex) Unsafe.As(ref Unsafe.Add(ref data, (DataOffset - PointerSize) + index * PointerSize)) = ex; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ref byte GetResultStorageOrNull() { const uint mask = (1u << (int)ContinuationFlags.ResultIndexNumBits) - 1; From fb2bd73e508583599ef0cbb9f58cefa5c6b92aaa Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 21 Apr 2026 17:19:07 +0200 Subject: [PATCH 2/2] Also SetException --- .../src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs index a71224cf399943..0eeea7e127dfd0 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs @@ -128,6 +128,7 @@ public bool HasException() return ((uint)Flags & (mask << (int)ContinuationFlags.ExceptionIndexFirstBit)) != 0; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetException(Exception ex) { const uint mask = (1u << (int)ContinuationFlags.ExceptionIndexNumBits) - 1;