Optimizing Uno Platform WebAssembly Applications for Peak Performance
source link: https://platform.uno/blog/optimizing-uno-platform-webassembly-applications-for-peak-performance/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Optimizing Uno Platform WebAssembly Applications for Peak Performance
- Uno Platform Team
- Published February 15, 2023
In this article, we will be discussing various tips and best practices for maximizing the performance of your Uno Platform WebAssembly applications, including ways to reduce startup times, improve rendering, and optimize memory usage. Whether you’re a seasoned developer or new to the Uno Platform, this article will provide valuable insights and techniques to help you create fast and efficient applications.
A natural question to ask is – “Why aren’t these options available by default?”. Fair question! The defaults we have set are there to optimize your ‘inner dev loop’ productivity. Once the Web app is deployed you can get significant performance improvements just by toggling a few options.
So, let’s dive in and start optimizing!
Steps to Optimize Performance
Make sure to build using the
Release
configurationdotnet build -c Release
on the command line in your CI pipeline). Debug configuration disables a lot of performance optimizations. This is the prime spot where we’ve prioritizet the “inner, developer, loop”. Just changing this option will get you 2x improvements or more, depending on the scenario.
Upgrade to the latest Uno.Wasm.Bootstrap packages (7.0.17 as of writing of this blog) to benefit from .NET 7 runtime. In order to benefit from this update, you’ll need to set the
TargetFramework
to compile your code with at least thenet7.0
.
By default, Wasm apps use the IL Interpreter, which is fast to build but less performant. Again, inner dev loop optimization. For deployed applications you should use AOT and/or Profiled AOT for your application. You can add the following to your Wasm project:
<PropertyGroup>
<WasmShellMonoRuntimeExecutionMode>InterpreterAndAOT</WasmShellMonoRuntimeExecutionMode>
</PropertyGroup>
To enable it, if building using Windows, make sure to have Python 3.8 (or later) and git installed on the command line.
Using the
InterpreterAndAOT
mode makes the application a lot faster but can make it bigger and longer to build. If this becomes a problem, you can use Profile Guided AOT. Make sure to generate your AOT profile by using as much as your app as possible.
Larger applications generally need a different GC configuration. Adjusting the configuration may be useful to limit the collection runs on large allocations.
Add the following to your `csproj` file:
<ItemGroup>
<WasmShellMonoEnvironment Include="MONO_GC_PARAMS" Value="soft-heap-limit=512m,nursery-size=64m,evacuation-threshold=66,major=marksweep" />
</ItemGroup>
You can adjust the nursery-size and soft-heap-limit based on your application’s memory consumption characteristics.
Here are some additional performance tips that may apply to your application.
About Uno Platform
For those new to the Uno Platform, it allows for creating pixel-perfect, single-source C# and XAML apps that run natively on Windows, iOS, Android, macOS, Linux and Web via WebAssembly. In addition, it offers Figma integration for design-development handoff and a set of extensions to bootstrap your projects. Uno Platform is free, open-source (Apache 2.0), and available on GitHub.
Next Steps
To upgrade to the latest release of Uno Platform, please update your packages to 4.7 via your Visual Studio NuGet package manager! If you are new to Uno Platform, following our official getting started guide is the best way to get started. (5 min to complete)
Tags:
Share this post:
Related Posts
In this blog, we’ll explore how Uno Platform and WebAssembly make it possible to develop …
Google Maps is the leading location data and visualization platform for the web, but the …
We’re always keeping an ear out for feature requests, bugs, and issues raised by the …
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK