Skip to content

Startup Performance

David Ortinau edited this page Apr 10, 2025 · 3 revisions

πŸ’¬ Copilot Chat Prompt

Review my .NET MAUI startup code, especially MauiProgram.CreateMauiApp and App.xaml.cs. Identify synchronous operations, service initialization, or large dictionary loading that could slow startup. Suggest what can be deferred or lazily loaded.

Start-up time impacts the first impression of your app. Slower startup is often caused by unnecessary synchronous work.

πŸ” What to Look For

  • Heavy logic in MauiProgram.CreateMauiApp()
  • DI container scanning assemblies or loading all services
  • Eager loading of large resource dictionaries or services

πŸ›  Fix Examples

  • Use deferred service loading in your dependency injection setup:
    builder.Services.AddSingleton<IMyService, MyService>(); // Eager load
    builder.Services.AddSingleton(provider => new Lazy<IMyService>(() => new MyService())); // Lazy load
  • Move background or optional tasks to after app load:
    MainPage.Appearing += async (_, _) => await PrefetchDataAsync();
  • Avoid synchronous file IO or large configuration parsing in CreateMauiApp():
    var config = File.ReadAllText("config.json"); // ❌ Synchronous call
    var config = await File.ReadAllTextAsync("config.json"); // βœ… Async alternative

πŸ“š Additional Resources


➑️ Next: Capture a Performance Trace

Clone this wiki locally