Container startup time matters when applications are frequently created and destroyed.
This is especially important for workloads such as:
Serverless applications
Short-lived jobs
Kubernetes workloads
Autoscaled APIs
Background workers
Batch processing
Build and deployment tasks
For a long-running application, startup may happen only once every few days or weeks.
For a highly dynamic container platform, the same startup cost can occur thousands of times.
Native AOT changes the application execution model by compiling .NET code to native code ahead of time. Native AOT applications do not require JIT compilation at runtime and are self-contained. Microsoft documents faster startup and smaller memory footprints as key benefits of the deployment model, particularly for workloads with many deployed instances.
.NET 11 continues to improve Native AOT, including runtime work such as faster interface dispatch. Preview 6 also includes smaller Native AOT SDK container images.
That makes startup benchmarking an important way to determine whether Native AOT is actually beneficial for a particular containerized application.
What Is Native AOT?
A normal .NET application can use JIT compilation at runtime.
A simplified model is:
.NET Application
|
v
CLR
|
v
JIT Compilation
|
v
Native Code
|
v
Application Execution
Native AOT changes this:
.NET Application
|
v
AOT Compiler
|
v
Native Binary
|
v
Container
|
v
Application Execution
The native binary does not need to perform JIT compilation when the container starts.
This can reduce work during the startup path, although the actual startup time still depends on the application, container image, operating system, initialization logic, and deployment environment.
Why Container Startup Matters
Consider a Kubernetes deployment:
Load
|
v
Kubernetes
|
+----------+----------+
| | |
v v v
Pod #1 Pod #2 Pod #3
|
v
Application
If traffic increases, additional pods may be created.
The overall response time can therefore include:
Scheduling
+
Image Availability
+
Container Creation
+
Application Startup
+
Readiness
Native AOT primarily affects the application portion of this sequence.
It does not automatically eliminate Kubernetes scheduling, image pulling, networking, or infrastructure delays.
This distinction is important when designing a benchmark.
Native AOT vs JIT-Based Containers
A useful comparison is:
| Characteristic | JIT-Based .NET | Native AOT |
|---|---|---|
| Runtime compilation | Yes | No JIT at runtime |
| Deployment | Runtime-based | Self-contained native executable |
| Startup work | Runtime initialization + JIT as needed | Native executable initialization |
| Reflection compatibility | Broad | Requires additional analysis |
| Dynamic code | Broad support | More restrictions |
| Architecture | Runtime-dependent | Target-specific |
| Container base | Runtime/ASP.NET images | AOT-compatible runtime-deps images |
| Optimization target | General runtime execution | Native published workload |
Native AOT is not simply a switch that makes every application better.
The deployment model has compatibility constraints that must be tested.
Define the Benchmark Objective
A useful benchmark should answer a specific question.
For example:
How does container readiness time change when
the same ASP.NET Core application is published
using the standard runtime model versus Native AOT?
This is better than:
Is Native AOT faster?
The first question can be measured.
The second is too broad.
Establish Two Builds
Create two comparable application builds.
Standard .NET Build
ASP.NET Core
|
v
JIT-Based Runtime
|
v
Container
Native AOT Build
ASP.NET Core
|
v
Native AOT
|
v
Native Binary
|
v
Container
Keep the application source, configuration, endpoint behavior, and test workload the same.
The deployment model should be the primary experimental variable.
Enable Native AOT
For a compatible project, Native AOT can be enabled through the project file:
<PropertyGroup>
<PublishAot>true</PublishAot>
</PropertyGroup>
Microsoft recommends configuring PublishAot in the project file because it controls more than the publish command itself, including analysis related to dynamic code usage.
Then publish for the target runtime:
dotnet publish \
-c Release \
-r linux-x64
The runtime identifier must match the deployment environment.
For example:
linux-x64
linux-arm64
are different native targets.
A binary compiled for one target architecture cannot simply be treated as a universal binary.
Build the Container
A simplified multi-stage Dockerfile can look like:
FROM mcr.microsoft.com/dotnet/sdk:11.0 AS build
WORKDIR /src
COPY . .
RUN dotnet publish \
-c Release \
-r linux-x64 \
-o /app/publish
FROM mcr.microsoft.com/dotnet/runtime-deps:11.0 AS final
WORKDIR /app
COPY --from=build /app/publish .
ENTRYPOINT ["./MyApi"]
The exact image tag should match the .NET version and supported image variant being tested.
Microsoft provides dedicated runtime-deps image variants for Native AOT scenarios. Its container-image documentation also identifies *-aot variants for supported distributions.
Why runtime-deps Is Used
A Native AOT application is already compiled into a native executable.
It does not require the normal .NET runtime image in the same way a JIT-based application does.
The runtime-deps images are designed for scenarios including self-contained and Native AOT applications. Microsoft also provides AOT-specific variants for supported distributions.
Conceptually:
JIT Application
|
v
ASP.NET Runtime Image
Native AOT
|
v
Native Binary
|
v
runtime-deps Image
The exact base image should be selected based on operating-system, globalization, architecture, and application requirements.
Do Not Benchmark the Build Stage
A common mistake is to measure:
Docker build
+
Image startup
as if both represent runtime performance.
They are separate concerns.
Native AOT can have a different build-time cost because native compilation occurs during publishing.
Measure:
Build Time
separately from:
Container Startup
This produces a much more useful engineering comparison.
Define Container Startup
"Startup" can mean several different things.
Possible definitions include:
T0
Container process starts
T1
Application process starts
T2
HTTP server starts listening
T3
Readiness endpoint succeeds
T4
First successful application request
For production scaling, readiness time is often more useful than simply measuring process creation.
For example:
Container Start
|
v
Application Start
|
v
Kestrel Listening
|
v
Initialization
|
v
/readiness = 200
Define the measurement point before comparing builds.
Add a Readiness Endpoint
For example:
app.MapGet(
"/readiness",
() => Results.Ok());
Then the benchmark can wait for:
GET /readiness
to return successfully.
This creates a consistent application-level startup signal.
In a real production application, the readiness condition may also include:
Configuration loading
Required dependency initialization
Database connectivity
Critical cache initialization
Do not add external dependencies to the benchmark unless they are part of the startup behavior you want to measure.
Measure With Docker
A simple manual test can start a container:
docker run \
--rm \
-p 8080:8080 \
myapi:aot
Then measure the time until:
GET /readiness
returns successfully.
For repeatable research, automate the process.
The benchmark should:
1. Start container
2. Record start timestamp
3. Poll readiness
4. Record ready timestamp
5. Stop container
6. Repeat
Repeat the Test
Never rely on one startup measurement.
Use multiple runs:
Run 1
Run 2
Run 3
Run 4
Run 5
...
Then report a distribution.
Useful metrics include:
| Metric | Purpose |
|---|---|
| Minimum | Fastest observed startup |
| Median | Typical startup |
| p95 | Tail startup behavior |
| Maximum | Slowest observed startup |
The number of runs should be sufficient for the workload and environment.
The important point is repeatability.
Separate Cold and Warm Conditions
Container startup can be affected by image availability.
Consider:
Cold Image
Image not locally available
|
v
Pull
|
v
Container Start
versus:
Warm Image
Image already available
|
v
Container Start
If you include image pulling, you are measuring:
Image Distribution
+
Container Startup
+
Application Startup
If you want application startup specifically, use an already available image.
Both measurements can be useful, but they answer different questions.
Benchmark Image Pull Separately
For deployment analysis, measure:
Image Size
+
Pull Time
+
Container Startup
+
Readiness
For runtime analysis, measure:
Already Available Image
+
Container Startup
+
Readiness
This prevents image-transfer time from hiding the effect of Native AOT.
Measure Image Size
Native AOT can be attractive for container workloads because it can produce compact runtime artifacts.
However, do not assume that every Native AOT container will be smaller than every JIT-based container.
Measure the actual images.
For example:
docker image inspect myapi:aot
docker image inspect myapi:jitted
Then compare:
Compressed Registry Size
Uncompressed Local Size
Layer Count
Largest Layers
Registry size is particularly relevant for deployment and autoscaling.
Measure Memory After Startup
Startup time is only one Native AOT characteristic.
Also measure memory:
Container Starts
|
v
Application Ready
|
v
Memory Measurement
Useful measurements include:
Container memory usage
Managed memory where applicable
RSS
CPU during startup
Microsoft documents smaller memory footprints as one of the benefits of Native AOT, but the actual result remains workload-dependent.
Measure CPU During Startup
Startup CPU can reveal why one build starts faster.
For example:
Startup
|
+-- CPU spike
+-- Runtime initialization
+-- JIT work
+-- Application initialization
A Native AOT application may have a different startup CPU profile.
Do not infer the reason solely from the final startup number.
Use runtime and container telemetry where available.
Test a Minimal API First
A minimal application can establish a controlled baseline.
For example:
var builder =
WebApplication.CreateBuilder(args);
var app =
builder.Build();
app.MapGet(
"/",
() => "Hello World");
app.MapGet(
"/readiness",
() => Results.Ok());
app.Run();
Benchmark this first.
Then benchmark the real application.
This separates:
Runtime/container overhead
from:
Application initialization
Test the Real Application
A minimal API benchmark is useful but insufficient for production decisions.
Join the conversation! Your thoughts help the community grow.