In .NET Maui apps something that's triggered a lot is the PropertyChanged so I decided to spend some time profiling it and looking for places where performance can be improved.
I did create a couple of Benchmark tests to measure it. It starts with a simple property changing on controls and after a more real world test, where a bunch of properties are set.
During my tests I found 3 main issues.
1. New instances of PropertyChangedEventArgs instantiated every time
2. High SolidColorBrush churn caused by implicit Color -> Brush conversions, which also amplified allocations in the bindable property storage (Dictionary<,>.Entry[]).
From my profiler session (running the benchmark as a console app) I could see:
-
· High SolidColorBrush allocation volume attributed to implicit conversions.
-
· Cost (observed run before fix):
-
· Microsoft.Maui.Controls.SolidColorBrush: 2,000 allocations, ~608,000 bytes
-
· This correlated with high bindable storage growth allocations:
-
· Dictionary<,>.Entry[]: ~471,056 bytes
3. Boolean boxing in VisualElement.CoerceIsEnabledProperty (exceeded profiler threshold).
From my profiler session (running the benchmark as a console app) I could see:
- · (BindableObject, object)
- · Cost (observed run):
- · ~1,000 boxed booleans
- · ~24,000 bytes
I believe that any improvement on this area is a huge win, since it's a hot hot path on real world applications.
In .NET Maui apps something that's triggered a lot is the
PropertyChangedso I decided to spend some time profiling it and looking for places where performance can be improved.I did create a couple of Benchmark tests to measure it. It starts with a simple property changing on controls and after a more real world test, where a bunch of properties are set.
During my tests I found 3 main issues.
1. New instances of
PropertyChangedEventArgsinstantiated every time2. High SolidColorBrush churn caused by implicit Color -> Brush conversions, which also amplified allocations in the bindable property storage (Dictionary<,>.Entry[]).
From my profiler session (running the benchmark as a console app) I could see:
· High SolidColorBrush allocation volume attributed to implicit conversions.
· Cost (observed run before fix):
· Microsoft.Maui.Controls.SolidColorBrush: 2,000 allocations, ~608,000 bytes
· This correlated with high bindable storage growth allocations:
· Dictionary<,>.Entry[]: ~471,056 bytes
3. Boolean boxing in VisualElement.CoerceIsEnabledProperty (exceeded profiler threshold).
From my profiler session (running the benchmark as a console app) I could see:
I believe that any improvement on this area is a huge win, since it's a hot hot path on real world applications.