Asynchronous programming is fundamental to modern .NET applications.
ASP.NET Core applications use asynchronous I/O to handle concurrent requests. Background workers use Task and ValueTask to coordinate operations. Database providers, HTTP clients, file APIs, and messaging libraries all depend heavily on asynchronous execution.
For years, the C# compiler has transformed an async method into a state machine that allows execution to pause at an await and resume later.
.NET 11 introduces a significant change to that model with Runtime Async, also referred to as Runtime Async V2.
Instead of relying entirely on compiler-generated async state machines, the runtime can manage async suspension and resumption itself. Microsoft documents improvements in stack traces, debugging, continuation handling, JIT integration, and async overhead. Runtime Async is still a preview feature, so the correct way to evaluate it is through controlled benchmarks rather than assuming every asynchronous workload will automatically become faster.
What Changes With Runtime Async?
Traditional C# async compilation transforms code conceptually like this:
public async Task<string> GetDataAsync()
{
var data = await LoadDataAsync();
return data.ToUpperInvariant();
}
into compiler-generated machinery that tracks the current execution state.
Conceptually:
Async Method
|
v
Compiler-generated State Machine
|
+---- Await
|
+---- Suspension
|
+---- Continuation
Runtime Async changes where much of this responsibility lives:
Async Method
|
v
Runtime-managed Async Execution
|
+---- Suspension
|
+---- Continuation
|
+---- Resumption
The goal is to reduce unnecessary overhead while making asynchronous execution easier to inspect and debug.
Microsoft describes Runtime Async as a step toward replacing compiler-generated async state machines with runtime-managed suspension and resumption.
Runtime Async Is a Preview Feature
Before testing it, understand its current status.
.NET 11 is still in preview, and Runtime Async is also a preview feature. To explicitly enable it in an application, add the following to the project file:
<PropertyGroup>
<TargetFramework>net11.0</TargetFramework>
<Features>runtime-async=on</Features>
</PropertyGroup>
For net11.0 projects, Microsoft notes that EnablePreviewFeatures is no longer required specifically for Runtime Async.
The runtime libraries themselves are compiled with Runtime Async enabled, providing broad functional and performance validation of the feature. Microsoft specifically invites feedback about throughput and library-size changes observed by developers.
Why Async Performance Is Difficult to Benchmark
It is tempting to benchmark two methods and conclude:
.NET 10 async = X
.NET 11 async = Y
That is not enough.
Async performance depends on several factors:
Whether the operation completes synchronously.
Whether an actual suspension occurs.
Whether the operation is CPU-bound or I/O-bound.
Whether
ExecutionContextis captured.Whether
AsyncLocal<T>is used.Whether
TaskorValueTaskis returned.Whether the method is JIT compiled.
Whether ReadyToRun is involved.
Whether NativeAOT is involved.
How frequently the operation executes.
How much work happens outside the async infrastructure.
A good benchmark should therefore isolate individual scenarios.
Scenario 1: Synchronous Completion
The first test should measure an async method where the awaited operation is already complete.
public static async Task<int> GetValueAsync()
{
return await Task.FromResult(42);
}
A simpler synchronous method provides a baseline:
public static int GetValue()
{
return 42;
}
The purpose is not to claim that asynchronous code should replace synchronous code.
Instead, this test helps determine how much overhead exists when an asynchronous method takes a synchronous fast path.
Runtime Async specifically includes JIT support for task-returning methods that complete synchronously. Microsoft reports that the JIT can compile a dedicated Runtime Async version instead of routing through an additional thunk.
Scenario 2: Actual Suspension
A more realistic asynchronous benchmark needs an actual suspension point.
For example:
public static async Task<int> GetDelayedValueAsync()
{
await Task.Delay(1);
return 42;
}
This introduces a real asynchronous continuation.
However, Task.Delay also introduces timer and scheduling behavior that can dominate the measurement.
For runtime-focused benchmarking, a custom asynchronous producer or controlled synchronization mechanism can sometimes provide a cleaner experiment.
The important principle is to understand what the benchmark is actually measuring.
Scenario 3: Multiple Await Points
Real applications often contain several asynchronous operations:
public static async Task<string> ProcessAsync()
{
var customer = await LoadCustomerAsync();
var orders = await LoadOrdersAsync(customer.Id);
var result = await BuildResultAsync(customer, orders);
return result;
}
This creates multiple suspension points.
Runtime Async introduces tail merging of async suspension points, which can reduce generated code size. Microsoft lists this among the Runtime Async performance improvements in the later .NET 11 previews.
A benchmark should therefore compare:
One await
Two awaits
Three awaits
Many awaits
rather than assuming that every method benefits equally.
Scenario 4: ExecutionContext
ExecutionContext carries ambient execution state across asynchronous boundaries.
One example is AsyncLocal<T>:
private static readonly AsyncLocal<string?> RequestId
= new();
public static async Task ProcessAsync()
{
RequestId.Value = "request-123";
await Task.Delay(1);
Console.WriteLine(RequestId.Value);
}
The runtime needs to preserve the appropriate execution context when continuations resume.
.NET 11 includes an optimization where async continuations can avoid unnecessary ExecutionContext capture and restoration when there is no ambient state that needs to be propagated. Microsoft states that Task, Task<T>, ValueTask, and ValueTask<T> benefit from this behavior.
This is particularly relevant to high-throughput services where asynchronous operations occur millions of times.
However, do not interpret this as meaning that AsyncLocal<T> is always expensive or that developers should remove it indiscriminately.
Measure the actual application.
Scenario 5: Task vs ValueTask
A benchmark should also distinguish between Task and ValueTask.
For example:
public static Task<int> GetTaskAsync()
{
return Task.FromResult(42);
}
and:
public static ValueTask<int> GetValueTaskAsync()
{
return ValueTask.FromResult(42);
}
These are not interchangeable performance optimizations.
ValueTask<T> can be useful when an operation frequently completes synchronously and allocation behavior matters, but it also has usage constraints.
Do not change every Task<T> API to ValueTask<T> simply because a benchmark shows a difference in one microbenchmark.
The API's consumption pattern matters.
Building a BenchmarkDotNet Test
BenchmarkDotNet is useful for comparing asynchronous methods under controlled conditions.
A simple benchmark might look like this:
using BenchmarkDotNet.Attributes;
[MemoryDiagnoser]
public class AsyncBenchmarks
{
[Benchmark]
public async Task<int> TaskFromResult()
{
return await Task.FromResult(42);
}
[Benchmark]
public int Synchronous()
{
return 42;
}
}
Run it in Release configuration:
dotnet run -c Release
The benchmark should be executed separately under each runtime configuration being compared.
Do not mix Debug and Release results.
What Metrics Should You Capture?
A meaningful async benchmark should collect more than execution time.
| Metric | Why It Matters |
|---|---|
| Mean | Average operation cost |
| Error | Measurement uncertainty |
| Standard deviation | Run-to-run variation |
| Allocated bytes | Memory pressure |
| GC collections | Garbage-collection impact |
| Throughput | Useful for server workloads |
| Code size | Relevant to runtime-generated machinery |
| Stack behavior | Useful for diagnostics |
BenchmarkDotNet's memory diagnoser can help measure allocation behavior:
[MemoryDiagnoser]
public class AsyncBenchmarks
{
// Benchmarks
}
If the feature is intended to reduce overhead, allocations should be measured alongside latency.
Cleaner Stack Traces
Performance is not the only change.
Runtime Async also changes how live stack traces appear.
With traditional compiler-generated async state machines, a live stack can expose compiler-generated infrastructure.
Runtime Async allows the actual asynchronous methods to appear more directly in the live stack.
Join the conversation! Your thoughts help the community grow.