.NET 8 Native AOT is Insane

Faster startup time and smaller memory footprints.

Alex Maher

--

Native AOT in a Nutshell

Native AOT stands out as a feature that lets you compile your applications into native code. This means your app can run on machines without needing the .NET runtime installed.

You add <PublishAot>true</PublishAot> to your project file, and voilà, you're on your way to experiencing significantly improved performance​​​​​​.

Here are some ASP.NET AOT app stats:

Performance Gains vs. Limitations

But it’s not all smooth sailing. You notice that not every ASP.NET Core feature is compatible with Native AOT. This requires you to be strategic about when and how you use it​​.

The Real-World

Let’s say you’re developing a gRPC service. By using Native AOT, you see a reduction in your app’s disk footprint and memory demand.

The startup time? Much faster.

It’s a noticeable improvement, but you’re also aware that you have to carefully navigate around the limitations​​.

C# 12 and Interceptors

With the introduction of .NET 8 and C# 12, Microsoft has taken a significant step in enhancing the compilation process, especially for native Ahead-of-Time (AOT) compilation. This enhancement is primarily enabled by a new feature known as “interceptors.”

What are Interceptors?

Interceptors in C# 12, an integral part of the .NET 8 ecosystem, allow for what can be described as code rerouting, enabling context-specific optimization during the compilation process.

These interceptors essentially provide a mechanism to modify code to make it compatible with native AOT​​​​.

While this feature certainly enhances performance and compatibility, especially in the context of native AOT compilation, it also raises several crucial questions and implications:

--

--

Alex Maher

.NET C# dev with 10+ yrs exp, self-taught & passionate web developer. Sharing tips & experiences in C# and web dev.