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

  • Hands On: New VS Code Insiders Build Creates Web Page from Image in Seconds

    New Vision support with GitHub Copilot in the latest Visual Studio Code Insiders build takes a user-supplied mockup image and creates a web page from it in seconds, handling all the HTML and CSS.

  • Naive Bayes Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the naive Bayes regression technique, where the goal is to predict a single numeric value. Compared to other machine learning regression techniques, naive Bayes regression is usually less accurate, but is simple, easy to implement and customize, works on both large and small datasets, is highly interpretable, and doesn't require tuning any hyperparameters.

  • VS Code Copilot Previews New GPT-4o AI Code Completion Model

    The 4o upgrade includes additional training on more than 275,000 high-quality public repositories in over 30 popular programming languages, said Microsoft-owned GitHub, which created the original "AI pair programmer" years ago.

  • Microsoft's Rust Embrace Continues with Azure SDK Beta

    "Rust's strong type system and ownership model help prevent common programming errors such as null pointer dereferencing and buffer overflows, leading to more secure and stable code."

  • Xcode IDE from Microsoft Archrival Apple Gets Copilot AI

    Just after expanding the reach of its Copilot AI coding assistant to the open-source Eclipse IDE, Microsoft showcased how it's going even further, providing details about a preview version for the Xcode IDE from archrival Apple.

Subscribe on YouTube

Upcoming Training Events