Skip to content

Set runtime-async compiler flag in Directory.Build.props - #4165

Merged
Mpdreamz merged 2 commits into
mainfrom
chore/dotnet-11-runtime-async
Nov 11, 2026
Merged

Mpdreamz merged 2 commits into
mainfrom
chore/dotnet-11-runtime-async

Conversation

@Mpdreamz

@Mpdreamz Mpdreamz commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Set <Features>runtime-async=on</Features> in Directory.Build.props so the Runtime Async codegen path is enabled for every project in the solution. The .NET 11 BCL already ships compiled with runtime-async=on; this flag extends that coverage to user code, producing cleaner live stack traces, lower async overhead, and NativeAOT-compatible suspension. See What's new in .NET 11 runtime — Runtime Async for the full feature description.

Affects: Automation

Prompt summary: PR 2 of the .NET 11 migration stack: record AOT baseline numbers and opt into the Runtime Async codegen path. The flag is the prep work; the AOT measurements are in this PR body rather than in code.

Why

The .NET 11 BCL ships compiled with runtime-async=on, meaning the standard library's async methods are already on the new codegen path. Without this flag, user code builds against an optimised BCL but the compiler leaves all user-defined async methods on the state-machine path. Setting <Features>runtime-async=on</Features> extends coverage to the docs-builder codebase.

Runtime Async V2 in .NET 11 RC 1 replaces compiler-generated async state machines with runtime-managed suspension and resumption. Instead of emitting <Method>d__N state-machine classes, the runtime itself tracks async execution. The most visible win is in live stack traces: compiler-generated async produces multiple infrastructure frames per method; Runtime Async shows the actual call chain directly.

What

Runtime Async opt-in

<Features>runtime-async=on</Features> added to the central PropertyGroup in Directory.Build.props, adjacent to <LangVersion>preview</LangVersion>. The Features property is a semicolon-separated list that MSBuild passes directly to csc. Our entry ends up appended after the SDK's own run-nullable-analysis=never entry — that entry is set by the SDK automatically for implicitly-triggered builds (IDE design-time, background restores) to skip the expensive nullable flow analysis pass; it does not appear in regular dotnet build invocations and is not something we set. To opt a project back out of Runtime Async, set <UseRuntimeAsync>false</UseRuntimeAsync> in that project file.

AOT baseline (osx-arm64, net11.0, Release)

Measured on preview.7 (the installed SDK). The Runtime Async codegen change lands fully in RC 1 — numbers on RC 1 / GA will differ, especially for binary size, because state-machine types are replaced with runtime-managed continuations.

Binary Publish time Size Cold startup (--help) Warm startup
docs-builder ~69 s 58 MB 113 ms ~25 ms
essc ~20 s 18 MB 136 ms —

Cold startup is measured immediately after dotnet publish when the binary is not in the kernel's page cache. Warm startup (binary already paged in from a previous run) drops to ~25 ms — matching the system-installed binary on the same machine. On CI, first invocation is cold; subsequent invocations in the same job are warm.

When the stack is rebased onto an RC 1 or GA SDK, async-heavy paths (the Markdown pipeline, the assembler's concurrent build phase, the Elasticsearch exporter) should see reduced AOT binary size and lower allocation pressure in high-throughput async code paths.

Verify

dotnet build                 # 0 errors
./build.sh unit-test         # all passed

Stack: 2 of 3, on top of #4163

🤖 Generated with Claude Code

@github-actions github-actions Bot 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.

APPROVE


What is this? | From workflow: PR Review

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

Base automatically changed from chore/dotnet-11 to main November 11, 2026 07:01
Mpdreamz and others added 2 commits November 11, 2026 08:01
Add <Features>runtime-async</Features> to Directory.Build.props. The .NET 11
BCL ships compiled with runtime-async=on; this extends coverage to user code.

In preview 7, the flag correctly passes -features:runtime-async to the Roslyn
compiler but does not yet change async state machine generation — state machine
types are still emitted. The flag is forward-compatible: when the Roslyn
implementation lands at GA, the setting is already in place.

AOT measurements (osx-arm64, net11.0, runtime-async flag set):
- docs-builder: 58 MB / ~69 s publish / 113 ms startup
- essc:         18 MB / ~20 s publish / 136 ms startup

Numbers are flat vs the net11.0 baseline (expected — no IL change yet).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
The correct MSBuild property to opt into Runtime Async is
<Features>runtime-async=on</Features>. The bare value
<Features>runtime-async</Features> is accepted by the compiler
but does not enable the feature.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@Mpdreamz
Mpdreamz force-pushed the chore/dotnet-11-runtime-async branch from 003e2a2 to bacb743 Compare November 11, 2026 07:01
@github-actions

Copy link
Copy Markdown
Contributor

@Mpdreamz
Mpdreamz merged commit def8025 into main Nov 11, 2026
59 of 60 checks passed
@Mpdreamz
Mpdreamz deleted the chore/dotnet-11-runtime-async branch November 11, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants