Optimizing Uno Platform WebAssembly Applications for Peak Performance

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 configuration dotnet 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 the net7.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)

Share this post: