Skip to content

Improve PropertyChanged performance scenarios #35302

@pictos

Description

@pictos

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions