Runtime Async in .NET 11: The Runtime Learns to await

Runtime Async in .NET 11: The Runtime Learns to await

I have been grinning at a benchmark table since .NET 11 shipped on November 10, and I want to share why. In the first part of this series we followed concurrency from Thread to the Task Parallel Library. In the second part we watched the 2012 async/await design get cheaper with every release, and we ended at its natural boundary: the runtime only ever sees the transformed state machine, and a synchronous Task chain still allocates one Task per level. This part is about what happens when the runtime itself takes part. My article on the .NET 11 just-in-time (JIT) compiler internals said Runtime Async “deserves its own treatment”. Here it is.

Improving the Model We Already Have

The most important sentence in this story is older than the feature. In 2023 the runtime team built a green threads prototype, measured it, and found it, if slightly slower, “competitive with the current async/await”. They still put it on hold, because introducing a new programming model has a price. A competitive prototype, shelved by one sentence: “We can likely provide more value to our users by improving the async model we already have.”

That is the thread through everything since. The follow-up .NET 9 experiment asked what would happen if async and Task were a direct part of the runtime. The answer was unusually clear: runtime async was “at least as good as compiler-async in all the configurations that we measured”, and it could be “a drop-in replacement”. The tracking issue opened in November 2024, .NET 10 carried a hidden preview, and .NET 11 went through seven previews. Stephen Toub counted 235 pull requests under the runtime-async label by mid-September, and by Preview 7 the release notes said the feature “continues to close the gap with (and now beat) the compiler-generated state-machine model.”

The way the team treated the design it was building on deserves a moment. Toub notes that the runtime and JIT had optimized the state machine pattern “heavily over the years, including combining the task, state machine, continuation, and ExecutionContext into a single allocation, but by the time the JIT sees the IL, the transformation has already happened”. That is the boundary Part 2 ended on, and it is also why the 2012 design could ship without a new runtime feature. The compiler-only design was so well put together that the library could keep improving underneath it for a decade.

And the team kept the promise that matters most. That experiment had floated skipping the save and restore of ExecutionContext and SynchronizationContext at method boundaries, and had measured, by its own account imperfectly, what full compatibility costs: 20% to 30% in the non-suspending case of a somewhat complex prototype function. The shipped design restores both anyway. The goal, in Toub’s words, is “100% behavioral compatibility: whether an async method is lowered by the language compiler or by the runtime is an implementation detail, and any observable semantic difference is a bug.” They paid for compatibility, so we do not have to. The .NET Conf 2026 session abstract counts Runtime Async, together with the updated memory safety model, among “the biggest changes we’ve ever delivered”. Big words. After running the benchmarks below, I am not going to argue.

What Changes: async Becomes a Bit in the Method Header

The C# you write does not change. No new syntax, no LangVersion=preview. What changes is the intermediate language (IL) that Roslyn emits. Toub shows the result for static async Task<int> CallerAsync() => await CalleeAsync();:

.method private hidebysig static
    class System.Threading.Tasks.Task`1<int32> CallerAsync() cil managed async
{
    call class System.Threading.Tasks.Task`1<int32> CalleeAsync()
    call int32 System.Runtime.CompilerServices.AsyncHelpers::Await<int32>(
        class System.Threading.Tasks.Task`1<int32>)
    ret
}

Compare that with the hand-lowered AnswerStateMachine from Part 2. There is no <CallerAsync>d__0 type, no IAsyncStateMachine, no MoveNext, no builder. As Toub puts it, async used to evaporate at compile time. Now it condenses instead. The method carries a new MethodImpl bit, MethodImplOptions.Async (0x2000, written async in IL syntax, defined in the runtime async spec), and the body calls AsyncHelpers.Await. The Roslyn design document describes the signature transform for Task, Task<T>, ValueTask and ValueTask<T>. The compiler cannot even tell whether a referenced assembly was compiled this way, because for the caller it makes no difference.

The runtime side is where my enthusiasm peaks. As Toub describes it, the runtime gives a Task-returning async method a double life. One identity has the signature everything else sees, Task<int> CallerAsync(), and is an adapter thunk that preserves the public contract. The other is an AsyncCall variant that effectively returns an int and has a hidden channel for a continuation. When one runtime-async method awaits another, the JIT can call the AsyncCall variant directly and receives the value, or a continuation if the callee really suspended. No Task<int> needed. The thunks work in both directions, so runtime-async code can await anything compiled the old way, and old code can call runtime-async methods without noticing. It is the idea from Part 2 (the machine never leaves the stack when the awaited operation is already complete), generalized across the whole call chain.

Opting in is a single line in the project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net11.0</TargetFramework>
    <Features>$(Features);runtime-async=on</Features>
  </PropertyGroup>
</Project>

The runtime support is always on in .NET 11 (the environment variable knob was removed in Preview 4). Compiling your own code this way is the separate, per-project choice, and the Learn page for the .NET 11 runtime still calls it a preview feature. It has needed no EnablePreviewFeatures since Preview 3.

Checking which mode you are in

Trust is good, reflection is better. I like to prove what a build contains instead of trusting the csproj, and this probe reads the method’s MethodImplAttributes and looks for the compiler’s state machine attributes:

using System.Reflection;
using System.Runtime.CompilerServices;

foreach (var m in typeof(Samples).GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly))
{
    bool runtimeAsync = (m.MethodImplementationFlags & MethodImplAttributes.Async) != 0;
    bool stateMachine = m.GetCustomAttribute<AsyncStateMachineAttribute>() is not null
                     || m.GetCustomAttribute<AsyncIteratorStateMachineAttribute>() is not null;
    Console.WriteLine($"{m.Name,-14} runtimeAsync={runtimeAsync,-5} stateMachine={stateMachine}");
}

public static class Samples
{
    public static async Task<string> AnswerAsync() { int value = await Task.Run(() => 21); return "The answer is " + value * 2; }
    public static async ValueTask<int> ValueTaskOfT() { await Task.Yield(); return 1; }
    public static async void AsyncVoid() => await Task.Yield();
    public static async IAsyncEnumerable<int> Iterator() { await Task.Yield(); yield return 1; }
}

Our familiar AnswerAsync from Part 2 is in there, unchanged. On the general availability (GA) SDK 11.0.100 with the switch on, AnswerAsync and ValueTaskOfT report runtimeAsync=True stateMachine=False, while AsyncVoid and Iterator report False and True. Runtime async covers the four return types Task, Task<T>, ValueTask and ValueTask<T>; async void, async iterators and custom task-like types with their own builders keep the classic transformation, which remains a perfectly good home for them. In my benchmark assembly (the five chain helpers from Part 2 plus the two async exception benchmarks) the compiler produced 7 state machine types with the switch off and 0 with it on, and every async method carried the 0x2000 flag.

The compact shape shows in file size too. Toub’s size probe builds ten Task<int> methods that each await the next. I reproduced it byte for byte with the GA SDK: SizeProbe.dll is 10,752 bytes with compiler state machines and 5,632 bytes with runtime async. One correction to my own earlier writing: in my .NET 11 performance and AI services post I called it “generated code”, but it is the size of the compiled assembly file (the Portable Executable file with its IL, metadata, headers and resources), not the machine code the JIT produces. The same post said runtime async is “expected to become the default in .NET 12” and later spoke of the moment “when .NET 12 makes it the default”. Toub’s wording is a hope, which I come back to at the end, and a hope is how I would write it today.

Measuring It on My Laptop

I ran my own suite on the GA bits, because I wanted to see it with my own eyes. The machine is an Intel Core Ultra 7 155H on Windows 11, with BenchmarkDotNet 0.15.8 and .NET 10.0.15 against .NET 11.0.0, on AC power. These are micro-benchmarks on a hybrid P/E-core laptop, so trust ratios and allocations more than nanoseconds. There are three jobs: .NET 10; .NET 11 with my benchmark assembly still compiled to state machines, as in Part 2 (the label “.NET 11 (app code: state machines)” means most of the shared framework underneath is already built with runtime async while my own methods are not); and the same runtime with my assembly compiled with runtime-async=on. Each benchmark process verified in [GlobalSetup] that its build matched the job.

The chains are the ones from Part 2, deeper: ten levels for completion and suspension, thirty levels for exceptions. Time per call and allocated memory:

Benchmark.NET 10.NET 11 (app code: state machines).NET 11 (runtime async)
Task<int> chain, completes synchronously181.96 ns / 720 B167.06 ns / 720 B90.65 ns / 72 B
ValueTask<int> chain, completes synchronously106.11 ns / 0 B89.44 ns / 0 B74.50 ns / 0 B
Chain with a real suspension (Task.Yield)2,060.50 ns / 1,023 B1,867.33 ns / 1,026 B1,818.30 ns / 768 B
30 levels, leaf throws143.40 μs / 82,512 B112.05 μs / 82,512 B21.83 μs / 2,400 B
30 levels, Task.Yield then throw144.08 μs / 83,572 B116.04 μs / 83,509 B17.20 μs / 4,591 B

The synchronous Task<int> chain goes from ten 72-byte tasks to a single one (where runtime-async code hands its result back to BenchmarkDotNet’s ordinary Task-returning method), and the time roughly halves. The ValueTask chain has nothing to allocate and still gets faster. The chain that really suspends allocates a quarter less, and its time difference between the two .NET 11 jobs sits inside the noise, so I will not claim a win there.

The exception rows are where I started grinning. With state machines, an exception crossing thirty levels turns into a bucket brigade. It is thrown, caught and rethrown at every await boundary, and the benchmark’s exception counter shows 31 exceptions per call. With runtime async it shows 1 (2 after a yield). Toub explains why: the compiler-generated MoveNext wraps its whole body in a try/catch so that an exception can be stored into the returned task, so every level adds a catch and a rethrow even though no source method has a handler, which is where the 31 comes from. Runtime async does not re-enter a frame without a handler. On the synchronous path the exception unwinds through the fused calls normally, and after a real suspension one catch in the dispatch loop walks past the handlerless continuation records and faults the root task once.

My numbers and Toub’s agree on the shape. His post (hardware not stated, RC-era packages) shows a two-layer completed chain at 21.221 ns and 144 B with the classic lowering against 6.151 ns and 0 B with runtime async. His 30-level exception chain with a yield, which my performance and AI services post already quoted, comes out at a ratio of 0.17; mine is about 0.15 (116.04 μs to 17.20 μs), with allocation falling from 81.6 KB to 4.5 KB. My absolute times are higher, and the machines and harnesses differ (his runs both lowerings in one process with Server GC), so only the ratios compare. The ratio of roughly one sixth matches, and allocation collapses in both, to 9% in his run and under 6% in mine.

Two results I report without explaining them. First, .NET 11 with my app code on state machines is faster than .NET 10 in four of five rows here (the synchronous Task<int> chain’s intervals overlap), yet Part 2’s five-level chain showed no clear gap between the two, and I did not isolate the cause. Second, with runtime async my synchronous-throw chain (21.83 μs) was slower than the throw-after-yield chain (17.20 μs), the reverse of the state-machine jobs. BenchmarkDotNet also flagged several rows as multimodal, among them all three synchronous Task<int> chain jobs, so rerun it before you quote me.

Where Toub’s table says: measure

I trust the feature more because its author shows his unflattering rows. In his exception table, depth 1 with a yield is slower with runtime async (8.211 μs against 6.308 μs, a ratio of 1.30). His summary is candid: the goal for .NET 11 is parity with .NET 10, runtime async is “already as good as or better than the older implementation in many important paths” but “isn’t yet fully optimized”, and his advice is to experiment with opting in, “just make sure to measure”. Confident, not cocky. That is the posture I want from a team shipping a foundational change.

Stack Traces You Can Read While the App Is Running

The part I expect to enjoy most in daily work is quieter than the benchmarks. It is what a live await chain looks like to people and tools. Learn’s sample prints a StackTrace from the innermost method of a three-level chain, and I ran the same thing on the GA SDK:

using System.Diagnostics;

await OuterAsync();

static async Task OuterAsync() { await Task.CompletedTask; await MiddleAsync(); }
static async Task MiddleAsync() { await Task.CompletedTask; await InnerAsync(); }
static async Task InnerAsync()
{
    await Task.CompletedTask;
    Console.WriteLine(new StackTrace(fNeedFileInfo: true));
}

With compiler-generated state machines the printed trace has 13 lines: every async method (and <Main>$) appears twice, with an AsyncMethodBuilderCore.Start frame in between. With runtime async it has 5: InnerAsync, MiddleAsync, OuterAsync and the two compiler-generated entry point lines (<Main>$ and <Main>). (I quote printed lines; StackTrace.FrameCount also counts hidden frames.) To be precise about scope, exception stack traces from catch (Exception ex) already look the same in both modes; the win is what you see live, in a debugger, a profiler or a dump. Debugger breakpoints and stepping through await boundaries arrived in Preview 2.

Profilers get their own upgrade. A new async profiler event stream (see the pull request) writes compact records into per-thread buffers. In the pull request’s synthetic benchmark the overhead at 100,000 async resumes and suspensions per second is under 1%, against about 45% for the older TPL events, and traces shrink by roughly an order of magnitude. The format is internal and may change, and Preview 7 extended the stream to classic state machines too, so tooling sees one representation of both.

Already in Your App Before You Touch a Switch

Most of the .NET runtime libraries have been built with runtime async since Preview 4, and so have the shared-framework-only libraries of ASP.NET Core. Libraries that also ship as NuGet packages, such as System.Text.Json, keep classic state machines even inside the shared framework. So your app on .NET 11 already runs runtime-async code in much of the framework, for example inside HttpClient and Kestrel. The libraries team moved its own code over in Preview 4, and the GA announcement is explicit that opting your own code in is a separate choice.

One related change needs careful wording. Preview 6 removes the ExecutionContext capture and restore from one kind of runtime-async continuation, the one used when awaiting an IValueTaskSource-backed ValueTask (dotnet/runtime #128323). The release notes list Task, Task<T>, ValueTask and ValueTask<T> as beneficiaries. In the pull request the code change is scoped to the runtime-async continuation infrastructure, and the classic state machine path already skipped a no-op restore in earlier versions. No numbers have been published, so I will not invent any: the framework’s own runtime-async continuations simply carry less baggage.

The rest of .NET 11 threading rhymes with the earlier parts of this series:

  • lock runs on the .NET 9 lock. Monitor in CoreCLR moved to managed code on top of System.Threading.Lock, with a thin lock in the object header that inflates under contention (#118371). Your lock statements stay exactly as they are. Separately, #129083 stores the condition used by Monitor.Wait directly on the lock, and Toub’s ping-pong Monitor.Wait/PulseAll benchmark goes from 4.194 μs to 3.517 μs.
  • Pipelines contention. System.IO.Pipelines uses System.Threading.Lock internally now, and on a 56-core ASP.NET JSON benchmark the maximum lock contention dropped from 483 to 66 per second (#130884, the lock switch plus three related changes), for about 2.6% more requests per second. A realistic end-to-end figure, and a modest one.
  • Thread pool. The lower scheduling overhead around small work items is covered in my performance and AI services article. The hill-climbing controller from Part 1 still manages the thread count, and the new batching of socket and I/O events lets idle workers steal whole subtrees of work, the TPL work stealing idea again.
  • Analyzers. CA2027 (Info severity) flags Task.WhenAny(work, Task.Delay(timeout)), which leaves a timer running, and points to Task.WaitAsync from .NET 6. CA1876 flags AsParallel() inside foreach, and EF1004 flags ToAsyncEnumerable() on an IQueryable.

Turning It On With Confidence

This is the checklist I would hand to my own teams. Call it enthusiasm with a measuring tape.

Opt in per project, and per target framework

The switch is a Roslyn feature flag, so it applies per assembly. If a project multi-targets, set it only for net11.0. I built net10.0;net11.0 and checked the output with reflection: the net10.0 assembly kept its state machine and the net11.0 assembly carried the async bit.

<PropertyGroup>
  <TargetFrameworks>net10.0;net11.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net11.0'">
  <Features>$(Features);runtime-async=on</Features>
</PropertyGroup>

Mixed assemblies interoperate through the thunks, so you can move project by project; the biggest effect appears when whole call chains are runtime async. A note for NuGet library authors: dotnet/runtime does not compile its out-of-band packages with runtime async, citing Mono compatibility, and ASP.NET Core leaves its standalone packages out because runtime async is incompatible with WebAssembly. The runtime’s own build also skips Android and Apple mobile targets. If your library may run on Mono, Blazor WebAssembly or mobile targets, keep it off or test there first.

Opt out per method, with an experimental attribute

For A/B comparisons inside one process there is an escape hatch. I checked on the GA SDK whether RuntimeAsyncMethodGeneration ships in the base class library (BCL). It does not, and without a declaration the compiler reports CS0246. The Roslyn doc says the attribute “is not defined in the BCL” and “may be removed when the feature ships in stable”, so you declare it yourself, and Roslyn recognizes it by name:

using System.Runtime.CompilerServices;

static class Chains
{
    [RuntimeAsyncMethodGeneration(false)]
    public static async Task<int> ClassicOuter() => await ClassicInner();

    [RuntimeAsyncMethodGeneration(false)]
    private static async Task<int> ClassicInner() { await Task.Yield(); return 42; }

    public static async Task<int> RuntimeOuter() => await RuntimeInner();

    private static async Task<int> RuntimeInner() { await Task.Yield(); return 42; }
}

namespace System.Runtime.CompilerServices
{
    // Experimental: user-declared, recognized by name and shape.
    [AttributeUsage(AttributeTargets.Method)]
    internal sealed class RuntimeAsyncMethodGenerationAttribute(bool runtimeAsync) : Attribute
    {
        public bool RuntimeAsync => runtimeAsync;
    }
}

In my probe, the annotated method kept its state machine (runtimeAsync=False stateMachine=True) and its unannotated siblings were runtime async. Treat it as a measurement tool, not a long-term API. The runtime team itself uses it to opt out BCL methods that use pooling builders (#128943).

Three things I tested so you can plan

  1. Pooling builders. Part 2 covered PoolingAsyncValueTaskMethodBuilder. With runtime-async=on, a method annotated with [AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))] is compiled as runtime async in my probe, so the pooling does not apply automatically. If you rely on pooling in a hot path, annotate that method with the attribute above, or measure whether runtime async already beats the pool for your shape.
  2. UseRuntimeAsync=false. The Learn page mentions this property as the per-project way out. I tried it in an application project with the GA SDK (-p:UseRuntimeAsync=false) and the methods were still compiled as runtime async. As far as I can tell it belongs to the dotnet/runtime and dotnet/aspnetcore repository builds. For apps, the opt-out is not setting Features, or the per-method attribute.
  3. Tools that look at shapes. [AsyncStateMachine] and the <Method>d__N types disappear, and live stacks get shorter. Anything that reflects on them, mocks around them, or parses stack frames sees a new shape. Semantics are unchanged: an AsyncLocal<int> set to 2 in a callee that awaits Task.Yield() is still 1 in the caller after the await, in both modes (I ran a small AsyncLocal<int> probe in both modes).

And measure after warm-up. Async versions only joined the tiering pipeline in Preview 7, so give a service time to settle before you compare. ValueTask remains an API design choice: as Toub writes, choosing between Task and ValueTask is still a decision about your public surface, and runtime async “doesn’t make every asynchronous operation allocation-free”. Continuations are heap objects, and a Task still appears wherever somebody stores or composes one.

Twenty-Four Years, and the Keyword Stayed the Same

Toub writes: “My hope is that it’ll be on by default starting in .NET 12.” A hope, not a commitment. If the usual cadence holds, .NET 12 should also be the next long-term support (LTS) release, though that is my inference from the release policy and not an announcement. Whatever happens, his advice is the line I would put on a poster: “Keep writing asynchronous code the way you want it to read” and “don’t contort source code to remove a clean await just because today’s implementation might allocate an intermediate Task.” As I wrote in the .NET 11 roadmap, this feature already belongs to the present tense.

In 2002 we got Thread and the ThreadPool. In 2005 BackgroundWorker and SynchronizationContext arrived, and the small C# 2.0 program from Part 1 still runs on .NET 11. In 2010 the TPL gave us Task. In 2012 the compiler learned to write continuations, and for fourteen years the libraries beneath it kept getting faster, until the runtime could take over the one job that no library could reach. Our little chain followed the same road: a StartNew and two ContinueWith lambdas in 2010, one await in AnswerAsync in 2012, and on .NET 11 the very same method carries the async bit instead of a state machine. The answer is still 42. Every era solved the problem of its day and became the foundation of the next. The keyword never changed. The async you typed in 2012 is still the async you type today. The difference is that, once you opt in, it no longer evaporates at compile time. It condenses into a bit in the method header and a cheap AsyncCall for the runtime.

If you have a service you care about, add the one line to a test project this week, run your own chain benchmark, and look at the exception row. I will keep my benchmark handy, and I am already looking forward to the .NET 12 previews.

Comments

VG Wort