Location>code7788 >text

What does Native AOT for .NET look like now?

Popularity:822 ℃/2024-09-19 11:33:42


The article I'm going to write today stems from yesterday's post in my circle of friends, "TheUWP modernizes UWP apps with .NET 9 and Native AOT support"[1], a conversation with one of my buddies made me want to take a comprehensive look at what's going on with Native AOT right now.

NET 9's Native AOT (Ahead-of-Time Compilation) is a technology that Microsoft is focusing on in the .NET 9 release to improve application performance.Native AOT technology allows .NET code to be pre-compiled into native code, resulting in faster startup times and more efficient execution.

In .NET 9, Microsoft has identified Native AOT as one of the key points to improve performance[2]. In addition, Microsoft announced initial support for the Universal Windows Platform (UWP), allowing developers to modernize and transform existing UWP applications using .NET 9 and Native AOT technologies. This initiative provides an upgrade path for UWP developers to improve their apps with the latest .NET and Native AOT technologies. NET 9's Native AOT is not limited to the UWP platform; it also supports older Windows 7 and XP environments, marking a breakthrough in compatibility for AOT technology. However, Native AOT support for the Android platform has not yet been completed, especially JNI (Java Native Interface) support, which is considered a larger feature request, and Native AOT support for WPF/Winform, which also needs to be completed only in .NET 10.

NET's Native AOT technology optimizes code at the compilation stage, resulting in smaller executables and faster startup. This breakthrough feature not only enables support for older Windows 7 and Windows XP environments, but also opens up new possibilities for developers who rely on legacy systems with high performance requirements. Specifically, in .NET 9, to ensure backward compatibility, support for the AOT (Ahead-of-Time) compiler in the X86 architecture is extended, and .NET 9 employs a carefully crafted compilation strategy that ensures compatibility with the Win7 and XP APIs, allowing code to run seamlessly and allowing developers to optimize their applications at the compilation stage to be able to run on older Windows systems. AOT compiler support for the LoongArch and Risc-V architectures continues to be refined by the community.

In .NET 9, the following specific advances have been made to Native AOT (Compile On Demand) support and JNI (Java Native Interface) support:

  • In .NET 9, two new properties were introduced that allow developers to design function switches. These feature switches can be used in .NET libraries (as well as by yourself) to toggle certain areas of functionality. If a feature is unsupported, the unsupported and unnecessary features will be removed when trimming or compiling with the Native AOT, thus reducing the size of the application.
  • In .NET MAUI tests, getting Java array elements by calling JNI performed worse than using and the new Span method. This suggests that the developers are considering how to optimize this process in future releases.
  • NET 9's support for Native AOT on the Android platform focuses on functional switches through new attributes and the ability to reduce the size of apps through Native AOT.

For developers, the following prior knowledge or skills are required to learn and adopt the Native AOT technology of .NET 9:

  1. Understanding of the .NET platformNET platform, including its architecture, runtime environment, and how to deploy applications on different platforms. This helps to understand how Native AOT technology integrates with the existing .NET ecosystem.

  2. Familiar with C# or F# programming language: Since .NET 9 supports development via C# or F#, knowledge of these programming languages is necessary. Additionally, understanding the advanced features of these languages will help to more effectively utilize the performance benefits that come with Native AOT.

  3. Understanding compiler principles: Native AOT (Native Application Optimized Translation) is a pre-compilation technique that allows developers to generate machine code directly instead of relying on JIT (Just-In-Time) compilation. Therefore, having some understanding of how the compiler works can help developers better understand and use theNative AOT technology[3]。

  4. Performance Optimization Experience: Since Native AOT aims to provide predictable performance and reduce resource consumption, it is beneficial to have some experience in performance optimization. This includes in-depth knowledge of memory management, code optimization, etc.

  5. Cloud Native and Microservices Architecture KnowledgeNET 9: While not required, knowledge of cloud-native applications and microservices architectures can enhance a developer's ability to build efficient, scalable applications when using .NET 9. This is because .NET 9 specifically emphasizes performance in these architectures, seeNET 9 RC1 released[4]。

RELATED:

  • [1] UWP modernizes UWP applications with support for .NET 9 and Native AOT:/s/lCgDOeaTuwmGagZWZG2AmQ
  • [2] In .NET 9, Microsoft has identified Native AOT as one of the key points to improve performance: ./shanyou/p/18015105
  • [3] Native AOT Technical Guide:/hez2010/p/17999838/guidance-for-dotnet-nativeaot
  • [4] .NET 9 RC1 Released./s/WabCosc39FlI3Wrylf7CbQ