Browse Source

Merge pull request #26198 from abpframework/mansur-dotnet11-article

Article about what is new in .Net 11 runtime
pull/26199/head
Ahmet Çelik 2 months ago
committed by GitHub
parent
commit
c78bc6acdf
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 516
      docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/ARTICLE.md
  2. 7
      docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/ASSET-LICENSE.md
  3. BIN
      docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/benchmark-results.png
  4. 33
      docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/benchmark-results.svg
  5. BIN
      docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/live-stack-comparison.png
  6. 38
      docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/live-stack-comparison.svg
  7. BIN
      docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/physical-logical-async.png
  8. 20
      docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/physical-logical-async.svg
  9. BIN
      docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/runtime-async-architecture.png
  10. 43
      docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/runtime-async-architecture.svg
  11. BIN
      docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/task-materialization.png
  12. 29
      docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/task-materialization.svg

516
docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/ARTICLE.md

@ -0,0 +1,516 @@
# .NET 11 Runtime Async: Cleaner Stack Traces and Faster Async Paths
## Introduction
Asynchronous code is everywhere in a modern .NET application.
An HTTP endpoint awaits an application service. The application service awaits a repository. The repository awaits a database call. Logging, authorization, retries, serialization, and network operations add more asynchronous layers around the same request.
The C# code can still look simple:
```csharp
public async Task<OrderDto> GetAsync(Guid id)
{
Order order = await _orderRepository.GetAsync(id);
return ObjectMapper.Map<Order, OrderDto>(order);
}
```
However, the implementation below `async` and `await` has not been simple. In .NET 10 and earlier versions, the C# compiler normally turns each async method into a generated state machine. This design works well, but it can add infrastructure frames to live call stacks, create intermediate task-related objects, and make production profiling more difficult.
.NET 11 starts changing that foundation with **Runtime Async V2**.
The source code and the async programming model do not change. The important change happens below the source code: more of the async transformation moves from the C# compiler into the runtime and the JIT compiler. This gives .NET more information at the moment it optimizes the method.
For developers, the main results are:
- Cleaner live async stack traces.
- Better stepping and debugging through async code.
- Opportunities to remove intermediate `Task` objects and allocations.
- Smaller generated IL for eligible async methods.
- Better optimization of common async paths.
- A new lower-overhead foundation for async profiling.
This article explains what changed, where you can observe the difference, how to measure it, and what you should consider before enabling the preview feature in a real application.
## The main change: async lowering moves closer to the runtime
Consider this small method:
```csharp
static async Task<int> ReadLengthAsync(
Stream stream,
CancellationToken cancellationToken)
{
var buffer = new byte[4096];
int bytesRead = await stream.ReadAsync(buffer, cancellationToken);
return bytesRead;
}
```
With the classic model, the C# compiler creates a state-machine type. It usually contains:
- A state number.
- An async method builder.
- Fields for parameters and local values that must survive an incomplete `await`.
- Awaiter fields.
- A generated `MoveNext()` method.
`MoveNext()` runs the method until an awaited operation is incomplete. It saves the required state and registers itself as the continuation. Later, it runs again and continues from the saved state.
Runtime and JIT optimizations have made this model much cheaper over many .NET releases. Still, by the time the JIT receives the method, the compiler has already expanded a small source method into a more complex state machine.
![Classic compiler lowering compared with .NET 11 Runtime Async](assets/runtime-async-architecture.png)
With Runtime Async, the compiler emits smaller, suspension-aware IL and marks the method as async in metadata. The runtime and JIT then manage more of the transformation. They can use runtime information to decide:
- Which values are really alive at a suspension point.
- How continuation state should be stored.
- Whether an intermediate `Task` must be materialized.
- Whether a direct async call can use a more efficient calling path.
- How the method should be optimized after it becomes hot.
The programming model remains the same. `await`, cancellation, exceptions, synchronous completion, and `ConfigureAwait` keep their existing meaning. Microsoft states that behavioral compatibility is an explicit goal; an observable semantic difference should be treated as a bug.
### Enabling Runtime Async in a .NET 11 project
Application code must currently opt in:
```xml
<PropertyGroup>
<TargetFramework>net11.0</TargetFramework>
<Features>$(Features);runtime-async=on</Features>
</PropertyGroup>
```
No new C# syntax is required. You do not need `LangVersion=preview` or `EnablePreviewFeatures` for this switch in a `net11.0` project.
The .NET 11 runtime libraries are already compiled with Runtime Async enabled. Your own application and library methods use the new lowering only when you enable the feature during compilation.
## Cleaner live async stack traces
The clearest developer-experience improvement is visible in a **live stack trace**.
This means the stack shown by:
- The debugger Call Stack window.
- `new StackTrace()` while the code is running.
- A profiler that inspects live execution stacks.
- Diagnostic code that captures the current stack.
### Runnable example
The complete project is included in `samples/AsyncStackTraceDemo`. Its important part is:
```csharp
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));
}
```
The included script builds three variants:
1. .NET 10 with compiler-generated async lowering.
2. .NET 11 with compiler-generated async lowering.
3. .NET 11 with Runtime Async enabled.
On PowerShell:
```powershell
./scripts/run-samples.ps1
```
On Bash:
```bash
chmod +x ./scripts/run-samples.sh
./scripts/run-samples.sh
```
### Observed output
The .NET 10 and .NET 11 classic builds both produced 13 live frames. The output included repeated infrastructure frames similar to:
```text
InnerAsync()
AsyncMethodBuilderCore.Start(...)
InnerAsync()
MiddleAsync()
AsyncMethodBuilderCore.Start(...)
MiddleAsync()
OuterAsync()
AsyncMethodBuilderCore.Start(...)
OuterAsync()
Main()
AsyncMethodBuilderCore.Start(...)
Main()
Main(string[] args)
```
The Runtime Async build produced 5 frames:
```text
InnerAsync()
MiddleAsync()
OuterAsync()
Main()
Main(string[] args)
```
![Live stack trace comparison: 13 classic frames and 5 Runtime Async frames](assets/live-stack-comparison.png)
The exact generated method names can differ between source layout, SDK builds, and Debug or Release configuration. The useful result is the shape of the stack: Runtime Async shows the application call chain directly and removes the repeated async builder infrastructure from this example.
### Important: this is a live-stack improvement
Do not describe this feature as a general fix for `exception.StackTrace`.
Exception stack traces from code such as the following were already cleaned up by the existing async infrastructure:
```csharp
try
{
await ProcessAsync();
}
catch (Exception exception)
{
Console.WriteLine(exception.StackTrace);
}
```
The .NET 11 improvement is most visible while inspecting **live execution**, not after catching an exception.
## Where the performance opportunities come from
Runtime Async does not make every async operation faster and it does not remove every allocation. It gives the runtime new opportunities that were difficult to see after the compiler had already created a state machine.
### 1. Fewer intermediate Task objects
Consider a common layered call chain:
```csharp
static async Task<int> A() => await B();
static async Task<int> B() => await C();
static async Task<int> C()
{
await Task.Yield();
return 42;
}
```
In the classic model, every method has its own transformed state and task-like result. When the pattern is a direct call followed by a direct `await`, Runtime Async can sometimes use a special async calling path and link continuation state instead.
If the chain completes synchronously, the result can flow through internal calls as a value. If it suspends, the runtime can link continuation records without requiring a separate intermediate `Task<int>` at every eligible edge.
![How Runtime Async can avoid some intermediate Task objects](assets/task-materialization.png)
The optimization is not possible when the `Task` is observable as an object. For example:
```csharp
Task<int> task = GetValueAsync();
pendingTasks.Add(task);
task.ContinueWith(LogCompletion);
return task;
```
Here, the program stores and manually observes the task. The runtime must preserve that behavior and materialize the object.
### 2. Smaller generated IL and binaries
The classic transformation creates an entry method, a generated type, state fields, a builder, and `MoveNext()` for each async method.
Runtime Async leaves a smaller method body for the runtime to transform. In a deliberately async-heavy size test published by Microsoft, ten small async methods produced these assembly sizes:
| Lowering | Assembly size |
|---|---:|
| Compiler-generated | 10,752 bytes |
| Runtime Async | 5,632 bytes |
This is not a promise that a complete application will become 48% smaller. The test was intentionally dominated by small async methods. The useful conclusion is that Runtime Async can reduce the per-method IL and metadata cost.
### 3. Better exception flow through deep async chains
Classic async state machines normally contain generated exception handling so that an unhandled exception can be stored in the returned task.
In a deep chain, an exception can be:
1. Caught by generated code in the inner method.
2. Stored in its task.
3. Read and thrown again by the caller's awaiter.
4. Caught by the caller's generated code.
5. Stored in another task.
Runtime Async can move through continuation records that have no real user exception handler and fault the observable root task more directly. This can reduce repeated throw, catch, and task-fault work in deep pass-through chains.
This optimization does not make exceptions a normal or recommended control-flow mechanism. It only makes the runtime-generated path less expensive where possible.
### 4. Skipping unnecessary ExecutionContext work
`ExecutionContext` carries ambient state across async boundaries. `AsyncLocal<T>` values are a common example. Tracing and request-correlation systems can also use ambient state.
.NET 11 can detect when a continuation has no context state to restore and skip an unnecessary capture-and-restore cycle. `Task`, `Task<T>`, `ValueTask`, and `ValueTask<T>` paths can benefit.
The effect is workload-dependent. A high-throughput library path with little ambient state may benefit more than an ASP.NET Core request path that uses `Activity`, tracing, and several `AsyncLocal<T>` values.
### 5. JIT improvements for async paths
.NET 11 also improves several details around Runtime Async:
- Runtime Async methods participate in tiered compilation, so hot methods can receive Tier 1 optimizations.
- The JIT recognizes common factories such as `Task.CompletedTask`, `Task.FromResult`, and `ValueTask.FromResult`.
- Suspension points can be tail-merged to reduce generated code size.
- Some continuation objects can be cached and reused.
- Direct tail-await paths can avoid unnecessary layers.
- Runtime Async supports ReadyToRun and NativeAOT scenarios.
- ReadyToRun compilation can inline eligible await-less Runtime Async calls.
These are implementation improvements. Application code should continue to choose `Task` or `ValueTask` based on API semantics and measured needs, not because Runtime Async exists.
## A reproducible benchmark
The package includes `benchmarks/AsyncPathBenchmarks`. It compares classic and Runtime Async lowering inside the same .NET 11 process. This isolates the lowering strategy better than comparing a .NET 10 process with a .NET 11 process, where many other runtime changes would also affect the result.
The benchmark uses a compiler-recognized `RuntimeAsyncMethodGenerationAttribute` to force classic lowering for selected methods. This attribute is experimental and is **not a public .NET API**. Use it only for controlled experiments like this one.
Run it with:
```bash
dotnet run \
--project benchmarks/AsyncPathBenchmarks/AsyncPathBenchmarks.csproj \
-c Release \
--filter "*"
```
The included job performs 3 warm-up iterations and 10 measurement iterations. For serious performance work, increase the iteration count and run on a quiet, dedicated machine.
### Results from the included run
Test environment:
- Ubuntu 24.04.3 LTS.
- Intel Xeon Platinum 8573C, with 9 logical cores available to the container.
- .NET SDK `11.0.100-rc.1.26425.128`.
- .NET runtime `11.0.0-rc.1.26425.128`.
- BenchmarkDotNet `0.16.0-preview.1`.
- Release configuration and Workstation GC.
| Method | Mean | Ratio | Allocated |
|---|---:|---:|---:|
| ClassicCompleted | 84.99 ns | 1.00 | 144 B |
| RuntimeCompleted | 15.83 ns | 0.20 | 0 B |
| ClassicYielding | 678.15 ns | 1.00 | 248 B |
| RuntimeYielding | 314.50 ns | 0.46 | 168 B |
![Benchmark results from the included .NET 11 RC1 run](assets/benchmark-results.png)
These values are **not a general performance claim**. The benchmark ran in a shared container, could not raise process priority, and the `ClassicCompleted` measurements had high variance. The full BenchmarkDotNet report is included in `results/benchmark-results.md`.
The results demonstrate how to measure the feature and show clear allocation differences in this small pattern. They do not tell us how much faster an ABP application, API endpoint, or database operation will become.
Microsoft's own benchmark of the same two-layer pattern also showed lower time and allocation for Runtime Async, but with different absolute numbers. That difference is exactly why you should run the benchmark on your hardware and then measure a realistic application workload.
### Benchmark hygiene
Runtime Async is a compile-time feature. When switching the feature on and off in the same project, force a rebuild. Otherwise, an incremental build can leave an assembly from the previous configuration in the output directory.
The included scripts use `--no-incremental` for this reason.
For a fair application benchmark:
- Use Release builds.
- Pin the SDK and runtime versions.
- Record OS, CPU, GC mode, and application configuration.
- Warm up tiered compilation before recording steady-state throughput.
- Measure latency percentiles, CPU, and allocations—not only requests per second.
- Run several independent processes or test rounds.
- Compare the same commit with only the Runtime Async switch changed.
- Test with your real third-party libraries and normal observability configuration.
## Where should the difference be visible?
Runtime Async has the best opportunity in code with many small async layers:
```text
HTTP endpoint
→ application service
→ authorization helper
→ retry or policy layer
→ repository
→ database or network operation
```
Possible observable effects include:
- Fewer managed allocations per request.
- Lower GC pressure at high request rates.
- Better throughput on async-heavy CPU paths.
- Smaller application or library assemblies.
- Cleaner debugger and profiler stacks.
The difference may be difficult to see when:
- Most request time is spent waiting for a slow database or remote API.
- The async call chain is shallow.
- Tasks are stored or otherwise observed as objects.
- Much of the hot path is in older third-party assemblies compiled with classic lowering.
- Tracing, logging, or `AsyncLocal<T>` usage requires ambient context flow.
- The application is limited by database capacity, locks, serialization, or network bandwidth.
A 100-millisecond database query can easily hide a small runtime improvement in end-to-end request latency. The same improvement may still appear in allocation rate, CPU use, or maximum throughput under load.
## Investigating async behavior in production
Production async problems usually appear as one of these symptoms:
- High latency but low CPU usage.
- Thread-pool queue growth.
- Unexpected allocation or GC pressure.
- Time spent in continuations or framework infrastructure.
- A request that starts on one thread and continues on another.
The last case is especially important. When an async method suspends, its physical thread stack unwinds. The continuation can later resume on a different thread.
![Physical thread stacks compared with a logical async call chain](assets/physical-logical-async.png)
A normal sampling profiler can see the code currently running on Thread 27, but the earlier physical stack from Thread 12 is gone. An async-aware profiler needs runtime events to rebuild the logical chain.
### Start with counters
Use counters to decide whether you need a more detailed trace:
```bash
dotnet tool install --global dotnet-counters
dotnet-counters monitor --process-id <PID>
```
Watch the signals that match the symptom, such as:
- CPU usage.
- Allocation rate and GC activity.
- Thread-pool thread count.
- Thread-pool queue length.
- Exception rate.
Counters are good for detecting a problem, but they normally do not show the full logical async call chain.
### Collect a short trace
Install `dotnet-trace`:
```bash
dotnet tool install --global dotnet-trace
```
Collect a short runtime and sampled-thread trace:
```bash
dotnet-trace collect \
--process-id <PID> \
--duration 00:00:00:30 \
--profile dotnet-common,dotnet-sampled-thread-time \
--output async-investigation.nettrace
```
The exact providers should follow the question you are investigating. More events create more data and more overhead. Start narrow, record for a limited time, and reproduce one known problem window.
Open the trace in a compatible tool such as Visual Studio's performance tools or PerfView. Tool support matters: a runtime can emit new events before every analysis tool presents them in a useful async view.
### What is new for profiling in .NET 11?
Traditional Task Parallel Library events can be very verbose in async-heavy applications. .NET 11 adds a new buffered async-profiler event pipeline. Its design uses:
- Per-thread buffers.
- Compact timestamp and instruction-pointer encoding.
- Batched event flushing.
- A small wrapper frame that helps connect CPU samples to a logical async continuation.
In the runtime pull request's synthetic measurements, the new stream produced much less trace data and low overhead at realistic event rates. Treat those values as design measurements, not as a guarantee for your service. The event format is internal and can change, and analysis tools must understand it before you receive the full benefit.
Follow these production rules:
- Measure trace overhead on a staging environment first.
- Keep collection windows short.
- Avoid collecting unnecessary providers.
- Check for dropped events and increase buffers only when needed.
- Run the tool with the required process permissions.
- Protect traces because they can contain application names, paths, exception messages, and business information.
### Keep distributed tracing in the picture
Runtime stacks and CPU traces answer questions about execution cost. `Activity` and OpenTelemetry traces answer a different question: where did the request spend wall-clock time across services, databases, and external calls?
For a production investigation, use both views when possible:
- Distributed trace: request latency and service boundaries.
- Runtime trace: CPU, GC, contention, threads, and managed call stacks.
- Application logs: business context and failure details.
Together, they are more useful than any one source alone.
## Preview limitations and production readiness
Runtime Async currently supports async methods returning:
| Return type or feature | .NET 11 Runtime Async status |
|---|---|
| `Task` | Supported |
| `Task<T>` | Supported |
| `ValueTask` | Supported |
| `ValueTask<T>` | Supported |
| `async void` | Uses classic compiler transformation |
| Async iterators / `IAsyncEnumerable<T>` | Uses classic compiler transformation |
| Custom task-like types and custom builders | Use classic compiler transformation |
Runtime Async is compatible with existing assemblies. New code can await libraries compiled with the classic model, and classic code can call Runtime Async methods. However, the largest optimization opportunities appear when more of a direct async call chain uses Runtime Async.
The important readiness facts are:
- .NET 11 is RC1 at the time of writing, not the final release.
- Runtime Async remains preview and opt-in for application code.
- Microsoft describes the .NET 11 performance goal as broad parity with .NET 10, not a universal speedup.
- Important paths are already equal or faster, but known slower cases still exist.
- Tooling support for new profiling data can arrive at different times.
- Performance results can change between RC1, the final release, and servicing updates.
For production, do not enable the feature only because a microbenchmark is faster. Test compatibility, performance, diagnostics, startup, publishing, and rollback in the same deployment model you use for the real application.
## Conclusion
Runtime Async is one of the most important runtime changes in .NET 11, even though it does not add new C# syntax.
It moves more async implementation work into the runtime and JIT, where .NET has better information for optimization. The most immediate improvement is easier debugging through cleaner live stacks. The longer-term opportunity is reducing the hidden cost of composing many small async methods.
The feature is also a good reminder about performance work: architecture creates an opportunity, but measurement tells us whether that opportunity matters in our application.
Keep writing clear async code. Use `Task` and `ValueTask` according to their API trade-offs. Then benchmark the application, inspect its traces, and let evidence decide when Runtime Async is ready for your production workload.
## References
- [What's new in .NET 11](https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-11/overview)
- [What's new in the .NET 11 runtime](https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-11/runtime)
- [Performance Improvements in .NET 11 — Stephen Toub](https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-11/)
- [High-performance EventSource runtime async profiler — dotnet/runtime PR #127238](https://github.com/dotnet/runtime/pull/127238)
- [dotnet-trace documentation](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-trace)
- [dotnet-counters documentation](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-counters)
- [dotnet-monitor documentation](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-monitor)

7
docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/ASSET-LICENSE.md

@ -0,0 +1,7 @@
# Visual asset license
All diagrams and charts in this folder were created specifically for this article package. They are licensed under the Creative Commons Attribution 4.0 International license (CC BY 4.0), with attribution to Mansur Besleney.
License text: https://creativecommons.org/licenses/by/4.0/
The benchmark chart uses measurements produced by the runnable benchmark included in this package. It does not reproduce a third-party image.

BIN
docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/benchmark-results.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

33
docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/benchmark-results.svg

@ -0,0 +1,33 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1600" height="980" viewBox="0 0 1600 980" role="img" aria-labelledby="title desc">
<title id="title">Runtime Async benchmark results from the included sample</title>
<desc id="desc">On .NET 11 RC1, the included two-layer benchmark measured classic and Runtime Async completed paths at 84.99 and 15.83 nanoseconds, and yielding paths at 678.15 and 314.50 nanoseconds. Allocations were 144 versus 0 bytes and 248 versus 168 bytes.</desc>
<defs><style>
.bg{fill:#f7f9fc}.panel{fill:#fff;stroke:#d9e1ec;stroke-width:2}.title{font:700 35px Arial,sans-serif;fill:#172033}.sub{font:400 20px Arial,sans-serif;fill:#5d6a7f}.head{font:700 25px Arial,sans-serif;fill:#172033}.axis{stroke:#aeb9c8;stroke-width:2}.classic{fill:#e97451}.runtime{fill:#3487d5}.label{font:400 19px Arial,sans-serif;fill:#334158}.value{font:700 19px Arial,sans-serif;fill:#172033}.legend{font:700 20px Arial,sans-serif;fill:#243248}.foot{font:400 18px Arial,sans-serif;fill:#637188}
</style></defs>
<rect class="bg" width="1600" height="980"/>
<text class="title" x="800" y="58" text-anchor="middle">Included microbenchmark: time and managed allocation</text>
<text class="sub" x="800" y="96" text-anchor="middle">.NET 11 RC1 · Release · two async layers · shared Linux test host</text>
<rect class="classic" x="590" y="120" width="24" height="24" rx="4"/><text class="legend" x="625" y="140">Classic</text><rect class="runtime" x="790" y="120" width="24" height="24" rx="4"/><text class="legend" x="825" y="140">Runtime Async</text>
<rect class="panel" x="70" y="180" width="700" height="330" rx="18"/><text class="head" x="110" y="225">Synchronously completed path — mean time</text><text class="sub" x="110" y="258">Lower is better · scale: 0–100 ns</text>
<text class="label" x="110" y="325">Classic</text><rect class="classic" x="250" y="294" width="424" height="44" rx="7"/><text class="value" x="690" y="323">84.99 ns</text>
<text class="label" x="110" y="398">Runtime</text><rect class="runtime" x="250" y="367" width="79" height="44" rx="7"/><text class="value" x="345" y="396">15.83 ns</text>
<line class="axis" x1="250" y1="445" x2="700" y2="445"/><text class="sub" x="250" y="475">0</text><text class="sub" x="700" y="475" text-anchor="end">100 ns</text>
<rect class="panel" x="830" y="180" width="700" height="330" rx="18"/><text class="head" x="870" y="225">Synchronously completed path — allocation</text><text class="sub" x="870" y="258">Lower is better · scale: 0–160 B</text>
<text class="label" x="870" y="325">Classic</text><rect class="classic" x="1010" y="294" width="405" height="44" rx="7"/><text class="value" x="1430" y="323">144 B</text>
<text class="label" x="870" y="398">Runtime</text><rect class="runtime" x="1010" y="367" width="4" height="44" rx="2"/><text class="value" x="1030" y="396">0 B</text>
<line class="axis" x1="1010" y1="445" x2="1460" y2="445"/><text class="sub" x="1010" y="475">0</text><text class="sub" x="1460" y="475" text-anchor="end">160 B</text>
<rect class="panel" x="70" y="550" width="700" height="330" rx="18"/><text class="head" x="110" y="595">Path with Task.Yield — mean time</text><text class="sub" x="110" y="628">Lower is better · scale: 0–750 ns</text>
<text class="label" x="110" y="695">Classic</text><rect class="classic" x="250" y="664" width="407" height="44" rx="7"/><text class="value" x="673" y="693">678.15 ns</text>
<text class="label" x="110" y="768">Runtime</text><rect class="runtime" x="250" y="737" width="189" height="44" rx="7"/><text class="value" x="455" y="766">314.50 ns</text>
<line class="axis" x1="250" y1="815" x2="700" y2="815"/><text class="sub" x="250" y="845">0</text><text class="sub" x="700" y="845" text-anchor="end">750 ns</text>
<rect class="panel" x="830" y="550" width="700" height="330" rx="18"/><text class="head" x="870" y="595">Path with Task.Yield — allocation</text><text class="sub" x="870" y="628">Lower is better · scale: 0–280 B</text>
<text class="label" x="870" y="695">Classic</text><rect class="classic" x="1010" y="664" width="399" height="44" rx="7"/><text class="value" x="1425" y="693">248 B</text>
<text class="label" x="870" y="768">Runtime</text><rect class="runtime" x="1010" y="737" width="270" height="44" rx="7"/><text class="value" x="1296" y="766">168 B</text>
<line class="axis" x1="1010" y1="815" x2="1460" y2="815"/><text class="sub" x="1010" y="845">0</text><text class="sub" x="1460" y="845" text-anchor="end">280 B</text>
<text class="foot" x="800" y="925" text-anchor="middle">Microbenchmark results vary by hardware and runtime build. Re-run the included project on your target environment.</text>
<text class="foot" x="800" y="952" text-anchor="middle">The classic and Runtime Async methods ran in the same .NET 11 process to isolate the lowering strategy.</text>
</svg>

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/live-stack-comparison.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

38
docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/live-stack-comparison.svg

@ -0,0 +1,38 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1600" height="980" viewBox="0 0 1600 980" role="img" aria-labelledby="title desc">
<title id="title">Live stack trace comparison</title>
<desc id="desc">Classic lowering displays 13 live stack frames including async infrastructure. Runtime Async displays 5 application frames for the same program.</desc>
<defs><style>
.bg{fill:#f7f9fc}.box{fill:#fff;stroke:#d7dfeb;stroke-width:2}.title{font:700 35px Arial,sans-serif;fill:#172033}.sub{font:400 21px Arial,sans-serif;fill:#5b687d}.head{font:700 26px Arial,sans-serif;fill:#172033}.code{font:400 18px Consolas,'Liberation Mono',monospace;fill:#243248}.plumb{font:400 18px Consolas,'Liberation Mono',monospace;fill:#b14a3b}.appbg{fill:#eaf5ff}.plumbbg{fill:#fff0ed}.pillA{fill:#e97451}.pillB{fill:#3487d5}.pill{font:700 18px Arial,sans-serif;fill:#fff}.note{font:700 21px Arial,sans-serif;fill:#22643d}
</style></defs>
<rect class="bg" width="1600" height="980"/>
<text class="title" x="800" y="58" text-anchor="middle">The same code, a much cleaner live stack</text>
<text class="sub" x="800" y="96" text-anchor="middle">Measured with .NET 11 RC1 and new StackTrace(fNeedFileInfo: true)</text>
<rect class="box" x="60" y="135" width="720" height="760" rx="18"/>
<rect class="box" x="820" y="135" width="720" height="760" rx="18"/>
<text class="head" x="100" y="185">Classic lowering</text><rect class="pillA" x="620" y="155" width="115" height="42" rx="21"/><text class="pill" x="677" y="183" text-anchor="middle">13 frames</text>
<text class="head" x="860" y="185">Runtime Async</text><rect class="pillB" x="1380" y="155" width="115" height="42" rx="21"/><text class="pill" x="1437" y="183" text-anchor="middle">5 frames</text>
<rect class="appbg" x="90" y="222" width="660" height="38" rx="6"/><text class="code" x="108" y="248">InnerAsync() : line 24</text>
<rect class="plumbbg" x="90" y="270" width="660" height="38" rx="6"/><text class="plumb" x="108" y="296">AsyncMethodBuilderCore.Start(...)</text>
<rect class="plumbbg" x="90" y="318" width="660" height="38" rx="6"/><text class="plumb" x="108" y="344">InnerAsync() infrastructure entry</text>
<rect class="appbg" x="90" y="366" width="660" height="38" rx="6"/><text class="code" x="108" y="392">MiddleAsync() : line 18</text>
<rect class="plumbbg" x="90" y="414" width="660" height="38" rx="6"/><text class="plumb" x="108" y="440">AsyncMethodBuilderCore.Start(...)</text>
<rect class="plumbbg" x="90" y="462" width="660" height="38" rx="6"/><text class="plumb" x="108" y="488">MiddleAsync() infrastructure entry</text>
<rect class="appbg" x="90" y="510" width="660" height="38" rx="6"/><text class="code" x="108" y="536">OuterAsync() : line 12</text>
<rect class="plumbbg" x="90" y="558" width="660" height="38" rx="6"/><text class="plumb" x="108" y="584">AsyncMethodBuilderCore.Start(...)</text>
<rect class="plumbbg" x="90" y="606" width="660" height="38" rx="6"/><text class="plumb" x="108" y="632">OuterAsync() infrastructure entry</text>
<rect class="appbg" x="90" y="654" width="660" height="38" rx="6"/><text class="code" x="108" y="680">Main() : line 7</text>
<rect class="plumbbg" x="90" y="702" width="660" height="38" rx="6"/><text class="plumb" x="108" y="728">AsyncMethodBuilderCore.Start(...)</text>
<rect class="plumbbg" x="90" y="750" width="660" height="38" rx="6"/><text class="plumb" x="108" y="776">Main() infrastructure entry</text>
<rect class="appbg" x="90" y="798" width="660" height="38" rx="6"/><text class="code" x="108" y="824">Main(string[] args)</text>
<rect class="appbg" x="850" y="222" width="660" height="68" rx="8"/><text class="code" x="878" y="263">InnerAsync() : line 24</text>
<rect class="appbg" x="850" y="310" width="660" height="68" rx="8"/><text class="code" x="878" y="351">MiddleAsync() : line 18</text>
<rect class="appbg" x="850" y="398" width="660" height="68" rx="8"/><text class="code" x="878" y="439">OuterAsync() : line 12</text>
<rect class="appbg" x="850" y="486" width="660" height="68" rx="8"/><text class="code" x="878" y="527">Main() : line 7</text>
<rect class="appbg" x="850" y="574" width="660" height="68" rx="8"/><text class="code" x="878" y="615">Main(string[] args)</text>
<text class="note" x="1180" y="727" text-anchor="middle">The application call chain is visible directly.</text>
<text class="sub" x="1180" y="768" text-anchor="middle">Useful in debugger call stacks, live diagnostic</text>
<text class="sub" x="1180" y="801" text-anchor="middle">logging, and supported profiling tools.</text>
<text class="sub" x="800" y="942" text-anchor="middle">This comparison is about live stacks. Caught exception stack traces were already cleaned up by the existing async infrastructure.</text>
</svg>

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/physical-logical-async.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

20
docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/physical-logical-async.svg

@ -0,0 +1,20 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1600" height="900" viewBox="0 0 1600 900" role="img" aria-labelledby="title desc">
<title id="title">Physical threads and the logical async call chain</title>
<desc id="desc">An async operation starts on thread 12, suspends for I/O, and resumes on thread 27. The logical request chain crosses both physical stacks, which is why async-aware profiling is needed.</desc>
<defs><style>
.bg{fill:#f7f9fc}.title{font:700 35px Arial,sans-serif;fill:#172033}.sub{font:400 21px Arial,sans-serif;fill:#5d6a7f}.lane{stroke:#b7c1d0;stroke-width:3}.thread{font:700 24px Arial,sans-serif;fill:#243248}.block{fill:#eaf5ff;stroke:#3487d5;stroke-width:3}.io{fill:#fff8df;stroke:#d7a928;stroke-width:3}.resume{fill:#eaf8ef;stroke:#35a663;stroke-width:3}.txt{font:700 20px Arial,sans-serif;fill:#243248}.small{font:400 18px Arial,sans-serif;fill:#44536a}.logical{stroke:#8a55c5;stroke-width:6;stroke-dasharray:12 9;fill:none;marker-end:url(#p)}.event{stroke:#8290a6;stroke-width:3;fill:none;marker-end:url(#a)}.legend{fill:#fff;stroke:#d9e1ec;stroke-width:2}
</style><marker id="a" markerWidth="12" markerHeight="12" refX="10" refY="6" orient="auto"><path d="M0,0 L12,6 L0,12 z" fill="#8290a6"/></marker><marker id="p" markerWidth="12" markerHeight="12" refX="10" refY="6" orient="auto"><path d="M0,0 L12,6 L0,12 z" fill="#8a55c5"/></marker></defs>
<rect class="bg" width="1600" height="900"/>
<text class="title" x="800" y="58" text-anchor="middle">A logical async operation can cross physical threads</text>
<text class="sub" x="800" y="96" text-anchor="middle">A normal CPU stack sees the current thread; an async-aware profiler reconstructs the request story.</text>
<text class="thread" x="80" y="210">Thread 12</text><line class="lane" x1="230" y1="202" x2="1510" y2="202"/>
<text class="thread" x="80" y="430">I/O</text><line class="lane" x1="230" y1="422" x2="1510" y2="422"/>
<text class="thread" x="80" y="650">Thread 27</text><line class="lane" x1="230" y1="642" x2="1510" y2="642"/>
<rect class="block" x="290" y="155" width="360" height="94" rx="14"/><text class="txt" x="470" y="193" text-anchor="middle">Request → service → repository</text><text class="small" x="470" y="225" text-anchor="middle">Physical stack exists on Thread 12</text>
<path class="event" d="M650 202 C720 202 720 422 800 422"/>
<rect class="io" x="800" y="375" width="310" height="94" rx="14"/><text class="txt" x="955" y="413" text-anchor="middle">Socket or database wait</text><text class="small" x="955" y="445" text-anchor="middle">Thread 12 is free to do other work</text>
<path class="event" d="M1110 422 C1190 422 1190 642 1260 642"/>
<rect class="resume" x="1210" y="595" width="300" height="94" rx="14"/><text class="txt" x="1360" y="633" text-anchor="middle">Continuation resumes</text><text class="small" x="1360" y="665" text-anchor="middle">Physical stack is now on Thread 27</text>
<path class="logical" d="M310 285 C560 340 760 535 1250 555"/>
<rect class="legend" x="330" y="730" width="940" height="110" rx="16"/><line class="logical" x1="380" y1="775" x2="540" y2="775"/><text class="txt" x="575" y="783">Logical async call chain</text><text class="small" x="575" y="816">It connects work that no longer shares one physical thread stack.</text>
</svg>

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/runtime-async-architecture.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

43
docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/runtime-async-architecture.svg

@ -0,0 +1,43 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1600" height="900" viewBox="0 0 1600 900" role="img" aria-labelledby="title desc">
<title id="title">Classic async lowering compared with .NET 11 Runtime Async</title>
<desc id="desc">The classic model creates a compiler-generated state machine before the runtime sees the method. Runtime Async emits compact async-aware IL and lets the runtime and JIT perform the lowering.</desc>
<defs>
<style>
.bg{fill:#f7f9fc}.panel{fill:#fff;stroke:#d9e1ec;stroke-width:2}.head{font:700 34px Arial,sans-serif;fill:#172033}.sub{font:400 22px Arial,sans-serif;fill:#58657a}.label{font:700 25px Arial,sans-serif;fill:#172033}.body{font:400 21px Arial,sans-serif;fill:#334158}.classic{fill:#fff2e8;stroke:#ee8a3b;stroke-width:3}.runtime{fill:#eaf5ff;stroke:#3487d5;stroke-width:3}.good{fill:#eaf8ef;stroke:#35a663;stroke-width:3}.arrow{stroke:#8290a6;stroke-width:4;fill:none;marker-end:url(#arrow)}.badge{font:700 18px Arial,sans-serif;fill:#fff}.foot{font:400 19px Arial,sans-serif;fill:#66748a}
</style>
<marker id="arrow" markerWidth="12" markerHeight="12" refX="10" refY="6" orient="auto"><path d="M0,0 L12,6 L0,12 z" fill="#8290a6"/></marker>
</defs>
<rect class="bg" width="1600" height="900"/>
<text class="head" x="800" y="62" text-anchor="middle">Who lowers an async method?</text>
<text class="sub" x="800" y="100" text-anchor="middle">The C# syntax stays the same; the implementation responsibility moves.</text>
<rect class="panel" x="70" y="140" width="700" height="680" rx="22"/>
<rect class="classic" x="120" y="180" width="600" height="80" rx="16"/>
<text class="label" x="420" y="229" text-anchor="middle">.NET 10-style compiler lowering</text>
<rect class="classic" x="185" y="315" width="470" height="76" rx="14"/>
<text class="body" x="420" y="361" text-anchor="middle">C# async method</text>
<path class="arrow" d="M420 392 L420 440"/>
<rect class="classic" x="185" y="450" width="470" height="126" rx="14"/>
<text class="label" x="420" y="493" text-anchor="middle">C# compiler</text>
<text class="body" x="420" y="533" text-anchor="middle">Performs the full transformation</text>
<path class="arrow" d="M420 578 L420 626"/>
<rect class="classic" x="130" y="636" width="580" height="118" rx="14"/>
<text class="body" x="420" y="678" text-anchor="middle">Generated type + MoveNext()</text>
<text class="body" x="420" y="715" text-anchor="middle">builder + saved fields + Task boundary</text>
<rect class="panel" x="830" y="140" width="700" height="680" rx="22"/>
<rect class="runtime" x="880" y="180" width="600" height="80" rx="16"/>
<text class="label" x="1180" y="229" text-anchor="middle">.NET 11 Runtime Async</text>
<rect class="runtime" x="945" y="315" width="470" height="76" rx="14"/>
<text class="body" x="1180" y="361" text-anchor="middle">The same C# async method</text>
<path class="arrow" d="M1180 392 L1180 440"/>
<rect class="runtime" x="945" y="450" width="470" height="126" rx="14"/>
<text class="label" x="1180" y="493" text-anchor="middle">C# compiler</text>
<text class="body" x="1180" y="533" text-anchor="middle">Emits compact async-aware IL</text>
<path class="arrow" d="M1180 578 L1180 626"/>
<rect class="good" x="890" y="636" width="580" height="118" rx="14"/>
<text class="body" x="1180" y="678" text-anchor="middle">Runtime + JIT manage suspension</text>
<text class="body" x="1180" y="715" text-anchor="middle">and materialize Tasks only when needed</text>
<text class="foot" x="800" y="864" text-anchor="middle">Runtime Async is an implementation change—not a new async/await programming model.</text>
</svg>

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/task-materialization.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

29
docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/task-materialization.svg

@ -0,0 +1,29 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1600" height="880" viewBox="0 0 1600 880" role="img" aria-labelledby="title desc">
<title id="title">Intermediate Task materialization</title>
<desc id="desc">Classic lowering has observable task-like boundaries at each async layer. Runtime Async can link continuations and create a Task only at an observable boundary, when semantics allow it.</desc>
<defs><style>
.bg{fill:#f7f9fc}.panel{fill:#fff;stroke:#d9e1ec;stroke-width:2}.title{font:700 35px Arial,sans-serif;fill:#172033}.sub{font:400 21px Arial,sans-serif;fill:#5d6a7f}.head{font:700 27px Arial,sans-serif;fill:#172033}.method{fill:#eaf5ff;stroke:#3487d5;stroke-width:3}.task{fill:#fff0ed;stroke:#e97451;stroke-width:3}.cont{fill:#eaf8ef;stroke:#35a663;stroke-width:3}.txt{font:700 22px Arial,sans-serif;fill:#243248}.small{font:400 19px Arial,sans-serif;fill:#425169}.arrow{stroke:#8290a6;stroke-width:4;fill:none;marker-end:url(#a)}.dash{stroke:#35a663;stroke-width:4;stroke-dasharray:10 8;fill:none;marker-end:url(#g)}.note{fill:#fff8df;stroke:#d7a928;stroke-width:2}
</style><marker id="a" markerWidth="12" markerHeight="12" refX="10" refY="6" orient="auto"><path d="M0,0 L12,6 L0,12 z" fill="#8290a6"/></marker><marker id="g" markerWidth="12" markerHeight="12" refX="10" refY="6" orient="auto"><path d="M0,0 L12,6 L0,12 z" fill="#35a663"/></marker></defs>
<rect class="bg" width="1600" height="880"/>
<text class="title" x="800" y="58" text-anchor="middle">Runtime Async can avoid some intermediate Task objects</text>
<text class="sub" x="800" y="96" text-anchor="middle">Example: A() directly awaits B(), and B() directly awaits C().</text>
<rect class="panel" x="60" y="140" width="720" height="620" rx="20"/><text class="head" x="420" y="190" text-anchor="middle">Classic lowering</text>
<rect class="method" x="115" y="240" width="180" height="75" rx="14"/><text class="txt" x="205" y="286" text-anchor="middle">A()</text>
<rect class="task" x="430" y="240" width="230" height="75" rx="14"/><text class="txt" x="545" y="286" text-anchor="middle">Task A</text><path class="arrow" d="M300 277 L420 277"/>
<rect class="method" x="115" y="370" width="180" height="75" rx="14"/><text class="txt" x="205" y="416" text-anchor="middle">B()</text>
<rect class="task" x="430" y="370" width="230" height="75" rx="14"/><text class="txt" x="545" y="416" text-anchor="middle">Task B</text><path class="arrow" d="M300 407 L420 407"/>
<rect class="method" x="115" y="500" width="180" height="75" rx="14"/><text class="txt" x="205" y="546" text-anchor="middle">C()</text>
<rect class="task" x="430" y="500" width="230" height="75" rx="14"/><text class="txt" x="545" y="546" text-anchor="middle">Task C</text><path class="arrow" d="M300 537 L420 537"/>
<path class="arrow" d="M205 320 L205 360"/><path class="arrow" d="M205 450 L205 490"/>
<text class="small" x="420" y="650" text-anchor="middle">Each layer has its own transformed state and task-like result.</text>
<rect class="panel" x="820" y="140" width="720" height="620" rx="20"/><text class="head" x="1180" y="190" text-anchor="middle">Runtime Async, when the boundary is not observed</text>
<rect class="method" x="875" y="240" width="180" height="75" rx="14"/><text class="txt" x="965" y="286" text-anchor="middle">A()</text>
<rect class="method" x="875" y="370" width="180" height="75" rx="14"/><text class="txt" x="965" y="416" text-anchor="middle">B()</text>
<rect class="method" x="875" y="500" width="180" height="75" rx="14"/><text class="txt" x="965" y="546" text-anchor="middle">C()</text>
<path class="dash" d="M965 320 L965 360"/><path class="dash" d="M965 450 L965 490"/>
<rect class="cont" x="1160" y="330" width="285" height="155" rx="16"/><text class="txt" x="1302" y="383" text-anchor="middle">Linked continuation</text><text class="small" x="1302" y="420" text-anchor="middle">No intermediate Task</text><text class="small" x="1302" y="450" text-anchor="middle">is required here</text>
<rect class="task" x="1160" y="535" width="285" height="75" rx="14"/><text class="txt" x="1302" y="581" text-anchor="middle">Observable root Task</text><path class="arrow" d="M1302 490 L1302 525"/>
<rect class="note" x="865" y="650" width="630" height="70" rx="12"/><text class="small" x="1180" y="680" text-anchor="middle">If code stores, inspects, or manually continues a Task,</text><text class="small" x="1180" y="707" text-anchor="middle">the Task remains observable and must still exist.</text>
<text class="sub" x="800" y="830" text-anchor="middle">This is an optimization opportunity, not a promise that every asynchronous operation becomes allocation-free.</text>
</svg>

After

Width:  |  Height:  |  Size: 4.6 KiB

Loading…
Cancel
Save