News

Microsoft Intros Native AOT for ASP.NET Core

In the new .NET 8 Preview 3, Microsoft introduced initial support for native Ahead-of-Time (AOT) compilation in the framework's web-dev component, ASP.NET Core.

While choosing the AOT publishing option provides multiple benefits in certain scenarios, it also introduces compatibility issues and other concerns, so the dev team is starting small, introducing the functionality incrementally. Microsoft Native AOT deployment guidance explains that native AOT support lets developers create a self-contained app, AOT-compiled to native code, that can run on machines that don't have the .NET runtime installed, resulting in benefits including, in one example, an 80 percent reduction in startup time and an 87 percent reduction in app size.

[Click on image for larger view.] Faster Startup, Smaller App (source: Microsoft).

Microsoft presented a bullet-point list detailing AOT benefits:

  • Reduced disk footprint: When publishing using native AOT, a single executable is produced containing the program along with the subset of code from external dependencies that the program uses. Reduced executable size can lead to:
    • Smaller container images, for example in containerized deployment scenarios.
    • Reduced deployment time due to smaller images.
  • Reduced startup time: Native AOT applications can show reduced start-up times, in part due to the removal of Just-in-Time (JIT) compilation. Reduced start-up means:
    • The app is ready to service requests quicker.
    • Improved deployment with container orchestrators that manage transitions from one version of the app to another.
  • Reduced memory demand: Native AOT apps can have reduced memory demands depending on the work being performed by the app. Reduced memory consumption can lead to greater deployment density and improved scalability.
[Click on image for larger view.] ASP.NET Core Feature Compatibility with Native AOT (source: Microsoft).

However, because not all ASP.NET Core features or commonly used ASP.NET Core libraries are compatible with native AOT (see chart above), the initial work focuses on enabling support for apps using Minimal APIs or gRPC, and deployed in cloud-native environments.

Thus Preview 3 includes a new "Enable native AOT publish" option in the "ASP.NET Core gRPC Service" project template, along with a new "ASP.NET Core API" project template that also includes that option for projects more focused on cloud-native, API-first scenarios.

[Click on image for larger view.] New 'Enable native AOT publish' Option (source: Microsoft).

Microsoft listed some key fundamental compatibility requirements for native AOT applications:

  • No dynamic loading (for example, Assembly.LoadFile)
  • No runtime code generation via JIT (for example, System.Reflection.Emit)
  • No C++/CLI
  • No built-in COM (only applies to Windows)
  • Requires trimming, which has limitations
  • Implies compilation into a single file, which has known incompatibilities
  • Apps include required runtime libraries (just like self-contained apps, increasing their size as compared to framework-dependent apps)

"Native AOT deployment is not suitable for every application, but in the scenarios where the benefits that native AOT offers are compelling, it can have a huge impact," Microsoft said in a blog post last week about ASP.NET Core updates in .NET 8 Preview 3. "While it's still early, we'd love for you try out native AOT support for ASP.NET Core in .NET 8 Preview 3, and share any feedback you have by leaving a comment here, or logging an issue on GitHub. Be sure to read the current known issues regarding ASP.NET Core and native AOT compatibility.

"In future previews, we're working to enable more features of ASP.NET Core and supporting technologies with native AOT, including JWT authentication, options validation, ADO.NET data access for SQLite and PostgreSQL, and OpenTelemetry. We're also working on improving the Visual Studio experience for configuring and working on ASP.NET Core projects targeting native AOT."

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

Subscribe on YouTube