As lead of a .NET 10 platform team, would you move a command-line deployment tool and a long-running pricing service to Native AOT, ReadyToRun or plain JIT, and why?
answer
- where each process spends its life
- startup versus steady state
- dependency audit by warnings
- per-platform build matrix
- measure both modes first
basics
~20 sDecide per workload: the short-lived deployment tool suits Native AOT if its dependencies are AOT-clean, else ReadyToRun; the pricing service usually stays on the JIT, with ReadyToRun for cold starts, since tiered JIT with dynamic PGO usually wins at steady state.
solid answer
~50 sI'd decide per workload, on measured numbers. The **deployment tool** runs for seconds, many times a day in pipelines, so startup dominates and **Native AOT** is the natural target, provided the build is clean: set `PublishAot`, treat IL2026 and IL3050 as errors, replace reflection-based serialization and any run-time code generation, and accept a per-platform build matrix, since Native AOT cannot cross-compile between operating systems. If a dependency blocks that, **ReadyToRun** still cuts JIT work with no compatibility risk. The **pricing service** runs for days, so steady-state throughput matters more than startup. Staying on the JIT keeps tier-1 recompilation with dynamic PGO tuned to the live workload; I'd add ReadyToRun if scale-out cold starts hurt, and consider Native AOT only when instance density or memory is the real constraint and the libraries support it. Anything that loads plugins stays on the JIT.
code
xml · 4 lines<PropertyGroup>
<PublishAot>true</PublishAot>
<WarningsAsErrors>$(WarningsAsErrors);IL2026;IL3050</WarningsAsErrors>
</PropertyGroup>go deeper
Know that Native AOT helps most for short-lived processes and that it removes features like loading assemblies at run time.
Explain why a long-running service benefits from tiered JIT and dynamic PGO, and how ReadyToRun sits between plain JIT and Native AOT.
Drive a migration with evidence: analyzers on through PublishAot, IL2026 and IL3050 as errors, replacements for reflection-based libraries, and a per-platform build matrix.
Own the policy: which workloads may adopt Native AOT, what proof each needs, how shared libraries declare compatibility, and when ReadyToRun or plain JIT is the better default.
## Frame the decision around where each process spends its life Native AOT, ReadyToRun and plain JIT differ mainly in **when** IL becomes machine code and **what stays possible afterwards**. A lead's job is to match that to each workload rather than adopt one mode everywhere. | | Deployment tool | Pricing service | Desktop plugin host | |---|---|---|---| | Lifetime | Seconds, many runs | Days or weeks | Hours | | Dominant cost | Startup | Steady-state throughput | Startup and extensibility | | Dynamic needs | Usually none | Library-dependent | Loads customer assemblies | | Natural choice | Native AOT, else ReadyToRun | JIT, plus ReadyToRun if cold start hurts | JIT, ReadyToRun for its own code | ## The deployment tool: a Native AOT candidate A short-lived tool spends much of its runtime starting up: loading assemblies, jitting the methods it touches and initializing libraries. Native AOT removes the JIT and trims unused code, which gives the biggest startup and memory gain. Before committing, check: 1. **Dependencies.** Set `PublishAot` in the project; the trim and AOT analyzers then run in every build and report problems as IL2026 (`RequiresUnreferencedCode`) and IL3050 (`RequiresDynamicCode`) warnings. 2. **Reflection and code generation.** Serializers, mappers or DI containers that rely on run-time reflection or `Reflection.Emit` need source-generated alternatives or must go. 3. **Build matrix.** Native AOT targets one runtime identifier per build and does not cross-compile between operating systems, so a tool shipped to Windows, Linux and macOS needs a build on each. 4. **Supportability.** Native debug symbols are produced separately and must be archived, and diagnostics support has some limitations; confirm your crash and support workflow still works. 5. **Size.** Every value-type generic instantiation is pre-generated, so measure the binary rather than assume it is small. If any of these blocks Native AOT, **ReadyToRun** is the low-risk middle step: the JIT and all dynamic features remain, while precompiled code cuts startup JIT work. ## The pricing service: usually stays on the JIT A long-running service amortizes startup over days. What matters is steady-state latency and throughput, and that is where the JIT has an edge Native AOT cannot match: **tiered compilation with dynamic PGO**, on by default since .NET 8, recompiles hot methods using profiles from the live workload, enabling guarded devirtualization and better layout. Native AOT code is fixed at publish. Options: - **plain JIT** when instances are few and long-lived; - **JIT plus ReadyToRun** when scale-out or restarts make cold start visible, since hot methods are still promoted to tier 1; - **Native AOT** when instance density, memory per instance or very frequent cold starts are the real constraint and every library supports it; the docs single out workloads with many deployed instances. ## Gates and governance - **Make regressions impossible.** In AOT-targeted projects, `<WarningsAsErrors>$(WarningsAsErrors);IL2026;IL3050</WarningsAsErrors>` turns new trim and AOT warnings into build errors. - **Shared libraries declare compatibility.** Internal libraries set `IsAotCompatible`, which enables the trim, single-file and AOT analyzers for them; apps can opt into `VerifyReferenceAotCompatibility` to flag references not marked compatible. - **Test fallbacks under the JIT.** `DynamicCodeSupport` set to `false` makes `RuntimeFeature.IsDynamicCodeSupported` return `false`, so fallback paths run in ordinary test jobs. - **Measure, then decide.** Compare startup time, working set and steady-state throughput for each mode on the real workload. ## A rollout plan 1. Turn on the analyzers by setting `PublishAot` in the tool's project and count the IL2026 and IL3050 warnings; that number sizes the work. 2. Fix or replace each flagged dependency, then make the two ids errors so the count cannot grow back. 3. Publish Native AOT binaries for each target platform in CI, alongside the existing JIT build, and run the tool's integration tests against both. 4. Ship the native build to a subset of pipelines, compare start time and failure rates, and keep the JIT build as a rollback until the numbers hold. 5. For the service, run the same comparison on a load test before changing anything in production. ## What not to do - Mandate Native AOT across the board: plugin hosts and reflection-heavy services pay heavily for little gain. - Disable tiered compilation to "get AOT-like" startup: it slows startup and loses dynamic PGO. - Treat warnings as optional because the app runs under `dotnet run`: the JIT tolerates code the native binary will not.
- What evidence would you ask for before approving Native AOT for the pricing service?Measurements of the same build in JIT, JIT plus ReadyToRun and Native AOT on a production-like load: startup to first request, working set, and steady-state latency percentiles and throughput after warm-up. Plus a clean build with the trim and AOT warnings as errors, a working crash-dump and symbol workflow, and a stated reason such as instance density that the gain actually serves.
- A shared internal library blocks the tool's Native AOT build with IL2026 warnings; what do you do?Treat it as library work, not an app suppression. The library team sets `IsAotCompatible`, fixes or annotates the reflection paths, often with source generation, and publishes a compatible version. Meanwhile the tool ships with ReadyToRun so it still gets a startup gain, and suppressions are allowed only where someone has proven the code is safe.
- Native AOT is always faster, so every service should use it.
- ReadyToRun and Native AOT are the same thing under different names.
- AOT warnings can be ignored because the app runs fine under the JIT.
- One Native AOT build can be shipped to Windows, Linux and macOS.
- A plugin host can move to Native AOT and keep loading plugins.