Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] use Lazy<T> for MauiContext properties
Context: https://github.com/unoplatform/performance/tree/master/src/dopes/DopeTestMaui Building upon dotnet#7996 and dotnet#8001, I noticed while profiling the sample app putting N `Label` on the screen: 405.02ms (2.3%) microsoft.maui!Microsoft.Maui.MauiContext.get_Context() 77.90ms (0.44%) microsoft.maui!Microsoft.Maui.MauiContext.get_Handlers() Meaning that around ~2.74% of the time was spent just calling these two properties. These properties hit Microsoft.Extensions each time to locate the service: public Android.Content.Context? Context => _services.GetService<Android.Content.Context>(); These are core-services that wouldn't change after startup, so should we just use `Lazy<T>` instead of doing a call like this each time? I also made use of `ANDROID`, as that is the preferred define to use in .NET 6+ instead of `__ANDROID__`: https://github.com/dotnet/designs/blob/a447d77bb53d189746ccd80c2d814064c2b6c606/accepted/2020/net5/net5.md#vary-implementation ~~ Results ~~ A `Release` build on a Pixel 5 device, I was getting: Before: 81.70 Dopes/s After: 91.94 Dopes/s
- Loading branch information