Uno Platform Does WebAssembly Threading Months Ahead of .NET 7
Uno Platform has beaten Microsoft to the punch when it comes to multi-threading in WebAssembly, the tech behind Microsoft's client-side Blazor web-dev framework.
Support for multi-threading in WebAssembly (or wasm) is on tap for .NET 7, coming in November, but Uno Platform already has it in its latest update, Uno Platform 4.4. Uno Platform says its open source offering "allows for the creation of pixel-perfect, single-source C# and XAML apps which run natively on Windows, iOS, Android, macOS, Linux and Web via WebAssembly."
Multi-threading in .NET 7 has been in the works for years, sparked by a December 2019 GitHub issue calling for "Multithreading which is available already in WEBASM to be exposed to Blazor Client side." As detailed in the February Visual Studio Magazine article titled ".NET 7 WebAssembly Plans: Mixed-Mode AOT, Multi-Threading, Web Crypto", Microsoft's Daniel Roth at that time announced "Support for multithreading in Blazor WebAssembly is planned for .NET 7. Plans can still change, so we'll see how it goes."
But on the Uno Platform it's already going.
"Another exciting update is experimental Threading support in .NET 7," Uno Platform said in a June 28 blog post.
Uno Platform, often partnering with Microsoft, has been active in WebAssembly innovations. For example, it was the first to provide the capability to build WebAssembly apps in Visual Studio on Windows using Ahead of Time (AOT) compilation. It also borrowed Xamarin tech to add brand-new memory profiler support to .NET WebAssembly and has been very active in helping to flesh out WinUI 3 technology. With v4.4, those innovations continue.
"Our team has been working with the .NET team on providing early feedback for the hard work they've been putting into enabling Wasm threading for the past few months," Uno Platform said yesterday. "This is another great open source win for everyone, as ultimately both .NET and Uno Platform communities will benefit from this feature. We are glad to be able to contribute to this journey by being one of the first to take Wasm threading to our community.
"Both Uno.UI and the Uno Bootstrapper have been updated to include threading support. On the Uno.UI side, this means that you can create Threads or Tasks and use the CoreDispatcher or DispatcherQueue to come back to the main thread. This is enables Web Apps to perform expensive tasks off the UI thread and avoid freezing the UI."
As intimated, Uno Platform isn't the very first to tackle such support, as evidenced by the Threads Proposal for WebAssembly project on GitHub, meant for discussion, prototype specification and implementation of a proposal for threads support in WebAssembly.
Uno Platform itself experimented with WebAssembly threading a couple years ago, when wasm multi-threading was primarily available through techniques like using WebWorkers and other mechanisms that let WebAssembly apps use traditional web multi-threading paradigms.
Microsoft's experimental WebAssembly multi-threading support can be tracked in the appropriately named "[tracking] Experimental WebAssembly multithreading support" GitHub issue in the dotnet/runtime repo, which lists high-level goals including:
- The threading runtime should be distributed in the same browser-wasm runtime pack
- Threading should be opt-in only
- The wasm bindings and runtime are thread-safe and co-op GC aware
In the Uno Platform 4.4 update, along with threading support, there are also many other new features, including:
- Fluid animations via Skottie integration
- High-fidelity rendering via TextBlock for Skia Rewrite
- Uno Platform Project default template updates
- WebAssembly performance updates (including WebAssembly exceptions support)
- New scenarios via new GamePad APIs support
Other assorted tweaks and minor changes include:
- We've made some changes to the way android drawables are resolved. This time, on net6.0 and later, we're generating the table of drawables instead of relying on reflection. This makes for a zero-cost startup for this part and saves about 40ms.
- On iOS and macOS, we've made numerous changes to interop costs, such as converting Color to CGColor without an intermediate, avoiding calling specific methods that could re-create managed objects during disposition to release pressure on the GC
- We've changed how SelectorItem handles selection animations to avoid using DateTime.Now as the source of time. In .NET 6 and later, such calls must go through libICU for localization, making it more expensive than a simple Stopwatch use.
In total, Uno Platform implemented and resolved more than 90 new feature requests and issues.
"Uno Platform 4.4 is our 4th release in 2022, keeping us on a once-in-six-weeks rapid release schedule we aim for," the company said. "The release packs numerous UI and performance improvements across all target platforms. First, on the UI side you'll be able to produce beautiful fluid animations on .NET Android, .NET iOS and Skia-based targets, as well as increase high-fidelity renderings of all your texts on Skia-based targets. Second, on the performance side we are including support for the most recent WebAssembly advances available in .NET 7 -- Wasm Threading and Exception handling. Lastly, we also enabled new input scenarios via GamePad API support and improved the default project templates."
David Ramel is an editor and writer for Converge360.