.NET MAUI Performance

Introduction

Performance is critical for delivering smooth, responsive apps across devices. This tutorial covers techniques to measure, analyze, and improve your .NET MAUI application's speed and memory footprint.

Measuring Performance

Use the built‑in Stopwatch for quick benchmarks and Microsoft.Maui.Graphics for rendering metrics.

using System.Diagnostics;

public static long Measure(Action action)
{
    var sw = Stopwatch.StartNew();
    action();
    sw.Stop();
    return sw.ElapsedMilliseconds;
}

// Example
long ms = Measure(() => LoadHeavyData());
Console.WriteLine($"Load took {ms} ms");

Reducing Memory Usage

Prefer ValueTask over Task for lightweight async, and recycle SKBitmap instances.

public async ValueTask<string> GetDataAsync()
{
    // implementation
}

// Reusing bitmaps
var bitmap = new SKBitmap(width, height);
using var canvas = new SKCanvas(bitmap);
// draw...

Optimizing UI Rendering

Leverage Layout optimizations, avoid excessive bindings, and use Compiled Bindings where possible.

  • Set CacheLength on CollectionView to reduce off‑screen layout.
  • Use GraphicsView for custom drawing with minimal overhead.

Profiling Tools

Visual Studio Diagnostic Tools, dotMemory, and the MAUI Profiler extension help identify bottlenecks.

ToolFocusLink
Visual Studio ProfilerCPU & MemoryDocs
dotMemoryMemory SnapshotsSite
MAUI ProfilerLayout & RenderTutorial

Best Practices

  1. Minimize layout passes – use Grid with fixed rows/columns where possible.
  2. Prefer ObservableCollection<T> with BatchUpdates for large data sets.
  3. Avoid heavy work on the UI thread – offload to Task.Run or BackgroundWorker.
  4. Enable Release build optimizations before publishing.

FAQ

How do I detect UI thread lag?

Use Device.StartTimer to schedule a small interval and compare actual vs. expected times.

What is the impact of XAML compilation?

Enabling XAML compilation ([XamlCompilation(XamlCompilationOptions.Compile)]) reduces load time and memory usage.