[android] improve performance of StrokeExtensions#24267
Merged
Conversation
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
PureWeen
approved these changes
Aug 16, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context: #23991
Context: https://github.com/chabiss/periodictable
In the above sample in
Debug-mode, a lot of time is spent in:If you drill-in, a lot of the time is spent in,
View.Background, which is called a lot overall as well:Reviewing
StrokeExtensions, it does callView.Backgroundover and over, many times.To fix this:
Call
View.Backgroundonce and store it in aMauiDrawable?local variable.Subsequent calls to methods in
StrokeExtensionspass the local variable along.View.Backgroundis now called many fewer times and the result is:This should improve the performance of controls that use
MauiDrawablelike<Border/>on Android.For the future, we're looking into other ways to improve Debug-mode performance at: