dotnet / dotnet/aspnetcore

[Blazor] Enable Blazor apps running inside of ASP.NET Core to be Native AoT compiled

Open
#51,598 18 comments 50 reactions 1 assignee Claimed by @javiercn View on GitHub
area-blazor enhancement NativeAOT Pillar: Technical Debt Priority:1 triaged
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

There are several issues around this topic, and none are very explicit.

This issue will track the work we need to do to make this happen.

AoT has become an important tech across the industry, with emphasis on cloud scenarios, performance and "leanness". As such, it's interesting for Blazor Applications (a subset at least) to be able to be compiled ahead of time.

AoT opens the door to new scenarios, such as:
- Running on devices with heavy constraints (e.g. IoT)
- Running on devices with constrained sandboxes (e.g. iOS). While .NET runs in these devices today, Native AOT is a guarantee that we can run anywhere.
- Providing Web Based UIs for CLI tools (e.g. dotnet tools).

It also enhances Blazor's ability to run on existing scenarios:
* Serverless (e.g. Azure Functions)
* Containers (e.g. Kubernetes)

In general, AoT brings in the following benefits:
* Reduced app size
* This is important for cloud scenarios where its desirable to achieve higher container density.
* Faster startup:
* This impacts cold starts of the application, which is important in serverless contexts.
* Scale out of rolling updates in Cloud scenarios.
* Reduced memory demand:
* AoT apps generally run with less memory compared to JIT apps, since there are many runtime components that are not needed.
* Increased performance:
* Many of the constraints imposed by AoT are addressed via optimizations that can be applied at compile time, which in many cases
leads to better performance.
* Enhanced security:
* AoT apps are less susceptible to runtime attacks, since the code is already compiled and there is no JITing happening at runtime.
* When running in container scenarios, you can "chisel" the container to only have the minimum code needed for the app to run, reducing the surface attack area.

## Goals/Scope of the work
* Investigate and list all the blockers that prevent the app from being AoT.
* Understand the available solutions for each problem (source generation, etc.)
* Identify the fixes that we think are valuable for other reasons (perf, better trimming, etc.)
* Prioritize the set of changes we want to tackle in .NET 9.0 to drive towards this scenario (low hanging fruit, performance, trimming)

## Reasoning

We only get the benefits of AoT if we remove all the blockers, so we want to reduce the cost as much as possible by making changes that provide immediate value for other reasons (perf, trimming, etc).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.