AOT (Ahead-of-Time) compilation compiles your .NET code directly to WebAssembly at publish time rather than interpreting IL at runtime. The result is dramatically faster execution for CPU-intensive operations.
When to Use AOT
- Heavy computation: data processing, graphics, simulations
- Where runtime performance matters more than download size
- AOT roughly doubles the app download size
Enabling AOT
<!-- In .csproj -->
<PropertyGroup>
<RunAOTCompilation>true</RunAOTCompilation>
</PropertyGroup>
// Or at publish time:
dotnet publish -c Release -p:RunAOTCompilation=true
Requirements
- Install wasm tools:
dotnet workload install wasm-tools - Build times are significantly longer with AOT enabled
- Not all .NET code patterns are AOT-compatible — test thoroughly
Options Compared
- Interpreter (default) — smallest download, slowest execution
- Full AOT — largest download, fastest execution
- Hybrid AOT — AOT hot paths, interpret cold paths — best balance
Reference: