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 for Converge360.

comments powered by Disqus

Featured

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube