AOT in Mixed Mode, Multi-Threading, Web Crypto — Visual Studio Magazine

0

News

.NET 7 WebAssembly Plans: Mixed Mode AOT, Multi-Threading, Web Crypto

In building .NET 7, Microsoft will continue to improve the functionality of WebAssembly, the technology behind client-side Blazor, with plans to bolster Ahead Of Time (AOT) compilation, multi-threading, and cryptography support.

Blazor WebAssembly is the name of this client-side component of Blazor, which enables web coding in C# instead of JavaScript. WebAssembly serves as an assembly language-like compilation target for executing C# code in the browser.

With the first preview of .NET 7 shipping this week, Microsoft outlined plans for WebAssembly functionality in a Publish about updates to ASP.NET Core, the web development framework where Blazor lives. If measured by the number of work items in the ASP.NET Core Roadmap for .NET 7Blazor gets the lion’s share of developer attention by far.

ASP.NET Core Roadmap for .NET 7
[Click on image for larger view.] ASP.NET Core Roadmap for .NET 7 (source: Microsoft).

According to this week’s article, some of the areas where broad improvements are being made to the .NET 7 development lifecycle include: “New Features in .NET WebAssembly: Mixed-Mode AOT, Multithreading, Web Cryptography.”

AOT in mixed mode
The functionality surrounding this first piece has been around for a while now, as AOT came to Blazor last May in a .NET 6 preview. At the time, Daniel Roth, Senior Program Manager for ASP.NET, said: “Blazor WebAssembly now supports Ahead-Of-Time (AOT) compilation, where you can compile your .NET code directly to WebAssembly for a significant boost in runtime performance. Blazor WebAssembly apps today run at using a .NET IL interpreter implemented in WebAssembly. Because .NET code is interpreted, this generally means that .NET code running on WebAssembly runs much slower than it would on a runtime. NET normal..NET WebAssembly AOT compilation solves this performance problem by compiling your .NET code directly into WebAssembly.”

Mixed-mode AOT involves taking parts of IL (intermediate language) code and compiling it into WebAssembly to run in the browser. It falls short of the “full” AOT, which cannot be done in Blazor for technical reasons.

The “Mixed Mode AOT” element in the Roth-edited announcement post was questioned in a reader comment:

Blazor doesn’t have a full AOT yet, as noted in Blazor AOT .Net6 Preview 7 – Still Downloading Dll #35302but this problem is closed and the complete AOT is marked as finished (Developers can AOT compile .NET applications in WebAssembly format), and now Microsoft is moving to mixed AOT as if full AOT is already there. Full AOT is quite essential for deploying applications to browsers with good startup performance and file size. I think it’s best for developers who want to deploy apps to browsers to ditch Blazor and focus on the job made in runtimelab on NativeAOT WASM which seems much closer to having a usable wasm compiler toolchain.

Here is Roth’s response:

You are correct that we still rely on the .NET IL interpretation in some cases when using Ahead Compilation (AOT) for WebAssembly. Indeed, some .NET runtime features still require it. So in this case “full” AOT really means that we’re compiling AOT as much as we can. Work is underway to further improve WebAssembly AOT to reduce the need to use the interpreter, but it’s unlikely we’ll be able to completely remove it given the limitations currently imposed by WebAssembly.

Please also note that if download size is an issue, AOT compilation in general is not going to help even if we could remove the need for interpretation altogether. AOT compiled code is usually larger than the original .NET IL instructions, about 2 times larger. As we further reduce the need for interpretation, we can reduce the size of the application somewhat by further reducing the .NET assemblies, but the application will still be larger than if it weren’t using some all AOT. WebAssembly AOT compilation helps improve runtime performance for CPU-intensive jobs.

We are also aware of NativeAOT LLVM’s backend work and can’t wait to see how it goes!

The lack of native AOT has been a .NET Core issue for some time, with Microsoft in 2020 releasing survey results indicating that the lack of AOT was preventing developers from using .NET Core more.

Is the lack of an officially supported native AOT option stopping you from using .NET more?
[Click on image for larger view.] “Does the lack of an officially supported native AOT option stop you from using .NET more?” (source: Microsoft).

Multi-threading
The problem of multi-threading, meanwhile, has been debated since December 2019 when a publish was opened calling for “multithreading which is already available in WEBASM to be exposed to the Blazor client side”. Over two years – and 69 comments – later, Roth posted the final comment to the thread yesterday: “Multithreading support in Blazor WebAssembly is planned for .NET 7. Plans may still change, so we’ll see how that happens .”

Crypto Web
This stems from a July 2020 publish: “Developers targeting browser-wasm can use Web Crypto APIs.” He says the development team would like to use the platform’s native encryption features and avoid shipping OpenSSL for the browser.

It also points to SubtleCrypto Documentation, which says, “The Web Crypto API’s SubtleCrypto interface provides a number of low-level cryptographic functions. Access to SubtleCrypto’s functionality is achieved through the subtle property of the Crypto object you obtain from of crypto ownership.” MozillaComment said the Web Crypto API is an interface allowing a script to use cryptographic primitives in order to build systems using cryptography.

But first, hybrid Blazor
Note that Roth said all of the above work is planned for “After completing Blazor Hybrid support for .NET MAUI, WPF, and Windows Forms”. Blazor Hybrid apps are native apps that can leverage web technologies such as HTML and CSS for additional functionality. So a hybrid app can use an embedded WebView control to render the UI web while taking advantage of the device’s native capabilities, as explained in last month. Visual Studio Magazine article “Edit local images/text from a .NET MAUI Blazor hybrid app.”

You can read more about what’s new in Blazor Hybrid in .NET 7 in the article titled “What’s Coming for Blazor Hybrid in .NET 7”.

Roth’s February 17 post on ASP.NET Core updates in .NET 7 Preview 1 indicates that once this work is complete, other improvements for Blazor (in addition to AOT stuff) include:

  • Improved hot reload support
  • Data binding improvements
  • More flexible pre-rendering
  • More control over the lifecycle of Blazor Server circuits
  • Improved support for micro-interfaces

Other ASP.NET Core areas where development investments are described by Roth include:

  • Performance: .NET 6 contained many performance improvements for ASP.NET Coreand we’ll be working to make ASP.NET Core even faster and more efficient in .NET 7.
  • HTTP/3: Support for HTTP/3 shipped as a preview feature in .NET 6. For .NET 7 we want to end it and make it a supported feature enabled by default. In future previews, you can expect to see advanced TLS features and other performance improvements in our HTTP/3 support.
  • Minimum APIs: Added support for endpoint filters and route aggregation as core primitives for minimal APIs. Also simplify authentication and authorization configurations for APIs in general.
  • gRPC: We are investing in gRPC JSON transcoding. This feature allows gRPC services to be invoked as RESTful HTTP APIs with JSON requests and responses.
  • R-signal: Added support for strongly typed clients and returning results from client invocations.
  • Shaver: We will be making various enhancements to the Razor compiler to improve performance, resiliency, and make it easier to improve tooling.
  • VMC: Improvements in endpoint routing, link generation and parameter binding.
  • Orleans: The ASP.NET Core and Orléans teams are exploring ways to further align and integrate the Orléans distributed programming model with ASP.NET Core. Orleans 4 will ship with .NET 7 and focuses on simplicity, maintainability, and performance, including human-readable stream identities and a new, optimized, version-tolerant serializer.

What’s new in Preview 1, meanwhile, were listed as follows:

  • Minimal API improvements:

    • Support for IFormFile and IFormFileCollection
    • Bind request body as Stream or PipeReader
    • Configuring JSON options
  • SignalR client source generator
  • Support for nullable patterns in MVC views and Razor Pages
  • Use JSON property names in validation errors
  • Improved console output for dotnet monitoring
  • Configure dotnet watch to always restart on coarse changes
  • Use dependency injection in a ValidationAttribute
  • Faster header parsing and writing
  • gRPC JSON transcoding

“We hope you enjoy this preview of ASP.NET Core in .NET 7 and are as excited about our roadmap for .NET 7 as we are!” Roth said in conclusion. “We look forward to hearing your experiences with this release and your thoughts on the roadmap. Let us know what you think by reporting issues on GitHub and commenting on the roadmap issue.”

About the Author


David Ramel is an editor and writer for Converge360.



Share.

Comments are closed.