Skip to content

[android] improve performance of StrokeExtensions#24267

Merged
PureWeen merged 1 commit into
dotnet:mainfrom
jonathanpeppers:OptimizeStrokeExtensions
Aug 16, 2024
Merged

[android] improve performance of StrokeExtensions#24267
PureWeen merged 1 commit into
dotnet:mainfrom
jonathanpeppers:OptimizeStrokeExtensions

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Context: #23991
Context: https://github.com/chabiss/periodictable

In the above sample in Debug-mode, a lot of time is spent in:

1.20s (3.3%) microsoft.maui!Microsoft.Maui.Platform.StrokeExtensions.UpdateBorderStroke(Android.Views.View,Microsoft.Maui.IBorderStroke)
0.42s (1.2%) microsoft.maui!Microsoft.Maui.Platform.StrokeExtensions.UpdateMauiDrawable(Android.Views.View,Microsoft.Maui.IBorderStroke)

If you drill-in, a lot of the time is spent in, View.Background, which is called a lot overall as well:

627.20ms (1.7%) mono.android!Android.Views.View.get_Background()

Reviewing StrokeExtensions, it does call View.Background over and over, many times.

To fix this:

  • Call View.Background once and store it in a MauiDrawable? local variable.

  • Subsequent calls to methods in StrokeExtensions pass the local variable along.

View.Background is now called many fewer times and the result is:

1.07s (2.90%) microsoft.maui!Microsoft.Maui.Platform.StrokeExtensions.UpdateBorderStroke(Android.Views.View,Microsoft.Maui.IBorderStroke)
0.34s (0.94%) microsoft.maui!Microsoft.Maui.Platform.StrokeExtensions.UpdateMauiDrawable(Android.Views.View,Microsoft.Maui.IBorderStroke,Microsoft.Maui.Graphics.MauiDrawable&)
0.33s (0.91%) mono.android!Android.Views.View.get_Background()

This should improve the performance of controls that use MauiDrawable like <Border/> on Android.

For the future, we're looking into other ways to improve Debug-mode performance at:

Context: dotnet#23991
Context: https://github.com/chabiss/periodictable

In the above sample in `Debug`-mode, a lot of time is spent in:

    1.20s (3.3%) microsoft.maui!Microsoft.Maui.Platform.StrokeExtensions.UpdateBorderStroke(Android.Views.View,Microsoft.Maui.IBorderStroke)
    0.42s (1.2%) microsoft.maui!Microsoft.Maui.Platform.StrokeExtensions.UpdateMauiDrawable(Android.Views.View,Microsoft.Maui.IBorderStroke)

If you drill-in, a lot of the time is spent in, `View.Background`,
which is called a lot overall as well:

    627.20ms (1.7%) mono.android!Android.Views.View.get_Background()

Reviewing `StrokeExtensions`, it does call `View.Background` over and
over, many times.

To fix this:

* Call `View.Background` once and store it in a `MauiDrawable?` local
  variable.

* Subsequent calls to methods in `StrokeExtensions` pass the local
  variable along.

`View.Background` is now called many fewer times and the result is:

    1.07s (2.90%) microsoft.maui!Microsoft.Maui.Platform.StrokeExtensions.UpdateBorderStroke(Android.Views.View,Microsoft.Maui.IBorderStroke)
    0.34s (0.94%) microsoft.maui!Microsoft.Maui.Platform.StrokeExtensions.UpdateMauiDrawable(Android.Views.View,Microsoft.Maui.IBorderStroke,Microsoft.Maui.Graphics.MauiDrawable&)
    0.33s (0.91%) mono.android!Android.Views.View.get_Background()

This should improve the performance of controls that use
`MauiDrawable` like `<Border/>` on Android.

For the future, we're looking into other ways to improve Debug-mode
performance at:

* dotnet/runtime#106491
@jonathanpeppers jonathanpeppers added perf/general The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf) platform/android labels Aug 15, 2024
@jonathanpeppers jonathanpeppers marked this pull request as ready for review August 16, 2024 14:14
@jonathanpeppers jonathanpeppers requested a review from a team as a code owner August 16, 2024 14:14
@PureWeen PureWeen merged commit 334866f into dotnet:main Aug 16, 2024
@samhouts samhouts added fixed-in-net9.0-nightly This may be available in a nightly release! fixed-in-net8.0-nightly This may be available in a nightly release! labels Aug 27, 2024
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

fixed-in-net8.0-nightly This may be available in a nightly release! fixed-in-net9.0-nightly This may be available in a nightly release! perf/general The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf) platform/android

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants