.NET MAUI: painfully slow debugging resolved with speedscope

If you experiment long painful startup times, or even very long view construction times during your app lifetime when debugging, you can enable XAMLC again by setting a hidden property.

.NET MAUI: painfully slow debugging resolved with speedscope

I was currently doing the MAUI migration of an app running on a big but slow device for an important client.
We had a big app running on an Android device with tons of views.
On Xamarin.Forms it was slow, on MAUI it seems faster, but only when all the views were constructed, during the constructions of the views it took forever.

But when I say forever I mean a view that was constructed within 10 seconds on Xamarin.Forms in DEBUG was taking 50 seconds on MAUI in DEBUG.

Basically I had to wait for 5 minutes to interact with the app, whereas in Xamarin, I waited 1 minutes and a half.

So I created an issue on the MAUI repo. The brilliant Jonathan Peppers appeared in a magical smoke and asked me to create a speedscope trace file.

Cause yes! Brave people, you can now profile quite easily your MAUI apps.

For that, you have to follow the path to wisdom: https://github.com/xamarin/xamarin-android/pull/8713/files

This is the updated procedure in .net 8 to create a speedscope trace file. Those are AMAZING, once you create one you can just drag and drop it to https://www.speedscope.app/. And you can see what method calls are taking forever.

This is the speedscope file for the app startup in DEBUG:

DEBUG speedscope file

Let's zoom in:

zoom-in

Err wut? All the time is spent in the LoadFromXaml ?? I thought that xaml was compiled!

Well it's not the case in fact, by default, in DEBUG, MAUI apps do NOT compile xaml. Are they dear @jonathanpeppers ?

Oh so is this a new decision made in MAUI dear @StephaneDelcroix ?

I see...

TL;DR if you experiment long painful startup times, or even very long view construction times during your app lifetime when debugging, enable XAMLC in DEBUG by setting this property in your csproj:

<PropertyGroup Condition=" '$(Configuration)' == 'Debug'>
    <_MauiForceXamlCForDebug>true</_MauiForceXamlCForDebug>
    ...
</PropertyGroup>

And you will back to the good old Xamarin.Forms behavior.

Sources

[Android] In debug the app is way way slower than in xf · Issue #20739 · dotnet/maui
Description I am currently doing the maui migration of an app running on a big but slow device for an important client. We have a big app running on a android device with tons of views. On XF it wa…
XamlCompilation does not work on Debug · Issue #8633 · dotnet/maui
Description XamlCompilation does not work on Debug configuration. Similar with: #3794. It looks like this is a known thing/issue. Any workaround for this? Is this intended to work only for Release…