Skip to sessions and notes

These session notes are AI-generated and may contain mistakes. Verify important details against the original recording.

Moving `dotnet` Ahead (of Time)!

Chet Husk

Session · 26:12 recording · 6 min read

At a glance

  • .NET CLI Native AOT architecture
  • -66% latency on dotnet --version (-80ms)
  • -100ms on tool listings & execution
  • Native Muxer + AOT library C ABI entrypoint
  • Strangler Fig fallback to CoreCLR via hostfxr

Executive Summary

Chet Husk details the engineering journey of transforming the .NET CLI into a Native AOT (Ahead-of-Time) binary in .NET 11. With billions of CLI invocations executed every month worldwide by human developers, CI/CD pipelines, and autonomous AI agents, shaving tens to hundreds of milliseconds off standard commands produces massive cumulative throughput and cost savings.

Headline Accomplishments:

  1. Measured Performance Wins: Core commands like dotnet --version run two-thirds faster (cutting 80 ms); dotnet tool list and tool invocations cut **100 ms** per invocation. Chained command sequences compound these savings dramatically.
  2. Dual-Engine Architecture (Muxer + Native AOT Library): The CLI is not a standalone executable, but a native AOT library loaded by the native .NET muxer via a C ABI entrypoint. Supported commands run purely AOT; unsupported commands gracefully fall back to CoreCLR via hostfxr ("Strangler Fig" architecture).
  3. Architectural Disciplines & SDK Root: Moving to Native AOT forced the team to eliminate fragile patterns like Assembly.Location and resolve unversioned vs. versioned SDK root directory ambiguities with dedicated domain abstractions.
  4. Binary Bloat Mitigation & "Size of Spy": Analyzing trimmer call graphs to eliminate "dominator" subgraphs (e.g. replacing a 5 MB BCL XmlReader dependency tree with a lightweight recursive-descent parser).
  5. Major SDK Packaging Win: Through symlink deduplication in tarballs and zips by Michael Simons, the .NET 11 SDK eliminated 53 MB compressed / 150 MB uncompressed (Linux x64) of redundant binaries, leaving overall SDK payloads and container images smaller despite adding native AOT binaries.
  6. Testing Native AOT at Scale: Creating the internal DN test harness to emulate muxer C-ABI invocations and enforce strict behavioral parity between AOT and managed execution paths.

Detailed Section-by-Section Breakdown

1. Global Scale of the .NET CLI & The 100ms Opportunity

Presenter: Chet Husk

The .NET ecosystem runs on dotnet. With global telemetry recording billions of command executions every month across developer terminals, agentic loops, and CI runners:

  • Saving 80–100 milliseconds per command eliminates thousands of aggregate hours of developer wait time.
  • Diagnostic commands like dotnet --version drop from ~120 ms to ~40 ms (a 66% latency reduction).
  • Tool listings (dotnet tool list) cut ~100 ms.
  • Tool execution (both global and local .NET tools) drops invocation overhead by another 100 ms.

.NET CLI Global Scale Chart
.NET CLI Global Scale Chart

Native AOT CLI Benchmark Numbers
Native AOT CLI Benchmark Numbers


2. Chained Execution & The AI Agent Multiplier

While individual 80 ms savings feel subtle during casual typing, modern workflows chain dozens of CLI operations. In automated environments (e.g., CI matrix builds or autonomous AI agents iterating through build, test, package, and tool validation loops), the reduced overhead compounds exponentially.

Compound Savings in Chained CLI Commands
Compound Savings in Chained CLI Commands


3. Native AOT Command Coverage: Today vs. Future Roadmap

In .NET 11, the native AOT execution bubble covers:

  • Diagnostic Commands: dotnet --version, dotnet --list-sdks, dotnet --list-runtimes.
  • Solution Management: dotnet sln commands (add, remove, list).
  • Tool Management & Execution: Listing, running, removing, and searching global/local tools; built-in subcommands like user-secrets.
  • Cached File-Based Applications: Second-run cached executions of .cs script files bypass JIT compilation and launch via AOT.
  • MTP Testing: Running Microsoft Testing Platform (MTP) tests with --no-build utilizes the native AOT path.

Future Roadmap:

  • Compiling MSBuild project evaluation into the AOT bubble.
  • Tool installation and restore (pending NuGet AOT JSON serialization).
  • The .NET new templating engine.

AOT Command Coverage and Roadmap
AOT Command Coverage and Roadmap


4. Architecture: The Muxer and the Native AOT Library

Chet revealed that the .NET CLI is not an AOT executable; it is a Native AOT shared library:

[ dotnet CLI Invocation ]
          │
          ▼
   [ .NET Muxer ]  (Native executable: dotnet.exe / dotnet)
          │
          ├──> 1. Resolves SDK version directory (e.g. sdk/11.0.100)
          │
          ├──> 2. Discovers Native AOT CLI library
          │         │
          │         ▼
          │    Calls exported C ABI entrypoint: execute_cli()
          │         │
          │         ├── [Is command in AOT Bubble?]
          │         │         │
          │         │         ├── YES ──> Runs purely Native AOT (Zero JIT, ~40ms)
          │         │         │
          │         │         └── NO  ──> Invokes hostfxr resolver
          │         │                       │
          │         ▼                       ▼
          └──────────────────────────> Starts CoreCLR & executes managed CLI DLL

This hybrid approach allows .NET 11 to deliver instant native startup for supported commands while preserving 100% backward compatibility for complex legacy tasks through managed fallback.

Muxer and Native AOT Library Architecture
Muxer and Native AOT Library Architecture


5. Architectural Disciplines: The SDK Root Hurdle

Building a native AOT library highlighted several architectural assumptions embedded in the codebase:

  • Fragile Reflection: Code relying on Assembly.GetExecutingAssembly().Location failed because native AOT binaries strip or nullify assembly file paths.
  • Ambiguous Directories: In managed execution, AppContext.BaseDirectory points to the specific SDK version folder (dotnet/sdk/11.0.100/). In a native AOT library hosted by the muxer, it resolved to the parent unversioned directory (dotnet/).
  • Domain Clarification: The team had to formalize an explicit SdkRoot domain abstraction with hosting-aware locator strategies, ensuring clean separation between CoreCLR and native execution contexts.

SDK Root Directory Architecture Hurdle
SDK Root Directory Architecture Hurdle


6. Pushing the Ecosystem: NuGet & MSBuild AOT Enablement

Because the CLI aggregates key .NET dependencies, the CLI team served as a catalyst for other teams:

  • NuGet: Partnered to eliminate reflection in package management JSON parsers, unblocking AOT tool installation.
  • MSBuild: Prototyping AOT MSBuild project file evaluation, opening the door for external tools and third-party CLIs to run fast evaluation without full runtime spin-up.

Ecosystem Dependencies: NuGet and MSBuild AOT
Ecosystem Dependencies: NuGet and MSBuild AOT


7. The Size Tradeoff & Binary Bloat Analysis

Bringing commands into the AOT bubble increases disk footprint:

  • Initial CLI command parsing added ~5 MB.
  • Tool execution logic added ~2 MB.

To evaluate these tradeoffs on pull requests, the team created automated PR size-diff gates and tools:

  • Size of Scope: IL trimmer reachability analyzer.
  • Size of Spy: Developed by Chet Husk to parse trimmer DGML dependency graphs and uncover "dominators" (isolated methods/classes that pull in massive downstream dependency subgraphs).

The XML Reader Dominator Case Study:

Parsing XML files initially dragged in the full BCL XmlReader. XmlReader supports XML Schemas (XSDs), which references network URI resolvers, which pulled in HTTP and cryptography libraries—adding 5 MB of binary bloat! By replacing it with a small, purpose-built recursive-descent parser, the team saved over 5 MB across every supported RID.

AOT Size Delta vs Millisecond Tradeoffs
AOT Size Delta vs Millisecond Tradeoffs

Size of Spy Trimmer Dominator Analysis
Size of Spy Trimmer Dominator Analysis


To offset the size of the new AOT binaries, Michael Simons investigated redundancy in the overall .NET SDK packaging:

  • Identified dozens of duplicate managed assemblies across runtime packs and SDK directories.
  • Leveraged tarball symlink support and content-based deduplication during packaging.
  • Results:
    • Removed 53 MB of compressed archive payload.
    • Eliminated ~150 MB of uncompressed disk space on Linux x64.
  • This net reduction easily absorbed the 15–20 MB native AOT libraries, leaving .NET 11 SDK container images smaller overall than .NET 10!

SDK Deduplication via Symlinks Reclaiming 150MB
SDK Deduplication via Symlinks Reclaiming 150MB


9. Verification & Parity Testing (DN Test Harness)

To guarantee flawless compatibility between the managed CLI and the native AOT library:

  • Standard unit tests failed to replicate the exact native muxer loading environment.
  • The team built DN, an internal test harness that simulates the native muxer’s C ABI invocation.
  • Parity tests execute test suites against both managed and AOT modes to verify identical console outputs, exit codes, and diagnostic streams.