An app that is slow to start gets uninstalled. These are the techniques with the biggest impact on the performance of a .NET MAUI app.
1. Simple layouts
Every nested layout level costs measuring and drawing time. A Grid with rows and columns often replaces three or four nested StackLayouts.
2. Compiled bindings
With x:DataType on pages and DataTemplates, bindings are resolved at compile time instead of through reflection at runtime.
3. Keep work away from startup
public partial class HomeViewModel(ICatalog catalog) : ObservableObject
{
[ObservableProperty]
public partial IReadOnlyList<Product> Featured { get; set; } = [];
// called by the page in OnAppearing, not in the constructor
[RelayCommand]
private async Task LoadAsync() => Featured = await catalog.FeaturedAsync();
}
Register services as transient or lazy, load data when the page appears and postpone everything the first screen does not need.
4. Trimming and AOT
In Release, trimming removes unused code and reduces the app size. On iOS and Mac Catalyst you can enable Native AOT, for faster startup and lower memory use:
<PropertyGroup Condition="'$(TargetFramework)' == 'net10.0-ios'">
<PublishAot>true</PublishAot>
</PropertyGroup>
5. Images
Use images sized for the screen, compressed formats and caching for those downloaded from the network. A ten-megapixel image in a thumbnail wastes memory and time.
Measure
Always test in Release configuration on real devices, including budget ones: the emulator on a powerful PC hides many problems.
Comments (0)
No comments yet.