Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Avoid re-creating Android Paint instances #13259

Merged
merged 10 commits into from
Sep 14, 2023

Conversation

MartinZikmund
Copy link
Member

@MartinZikmund MartinZikmund commented Aug 15, 2023

GitHub Issue (If applicable): closes #13258, closes #11685

PR Type

What kind of change does this PR introduce?

  • Performance

What is the current behavior?

Brush always creates new Paint instances.

What is the new behavior?

BorderLayerRenderer and Shape both keep two static instances of Paint alive throughout the application lifetime, reusing them whenever needed. Because rendering happens on UI thread, this is not a problem - the approach is similar to the reuse of corner radius arrays.

Copilot Summary

🤖 Generated by Copilot at 59d9ca7

This pull request improves the performance and memory usage of various Brush classes and the Border control on Android by reusing and modifying Paint instances instead of creating new ones. It also refactors some code to follow the project's style guidelines and adds error handling and validation where needed. It updates the Brush abstract methods and the corresponding tests to reflect the new API. It affects the files BorderLayerRenderer.Android.cs, AcrylicBrush.Android.cs, Brush.Android.cs, SolidColorBrush.Android.cs, Shape.Android.cs, Given_RevealBrush.cs, RadialGradientBrush.Android.cs, RevealBrush.Android.cs, GradientBrush.Android.cs, ImageBrush.Android.cs, and XamlCompositionBrushBase.Android.cs.

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

Internal Issue (If applicable):

@github-actions github-actions bot added the platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform label Aug 15, 2023
@MartinZikmund MartinZikmund force-pushed the dev/mazi/android-paint-reuse branch from f3ac8f0 to d8f8c3e Compare August 15, 2023 13:24
@MartinZikmund MartinZikmund force-pushed the dev/mazi/android-paint-reuse branch 2 times, most recently from 8046a18 to fb7be39 Compare August 18, 2023 10:12
@jeromelaban
Copy link
Member

@MartinZikmund just a few breaking changes to mark are left.

@jeromelaban jeromelaban marked this pull request as draft August 25, 2023 03:04
auto-merge was automatically disabled August 25, 2023 03:04

Pull request was converted to draft

@MartinZikmund MartinZikmund force-pushed the dev/mazi/android-paint-reuse branch from fb7be39 to 371ec88 Compare September 5, 2023 13:10
@MartinZikmund MartinZikmund marked this pull request as ready for review September 5, 2023 13:23
@MartinZikmund
Copy link
Member Author

@jeromelaban made the method private protected as a breaking change, will adjust diffignore when the CI fails, otherwise should be good to approve

@MartinZikmund MartinZikmund force-pushed the dev/mazi/android-paint-reuse branch from 849dc1d to b40ea7d Compare September 5, 2023 17:03
@github-actions github-actions bot added the area/build Categorizes an issue or PR as relevant to build infrastructure label Sep 6, 2023
src/Uno.UI/UI/Xaml/Media/Brush.Android.cs Outdated Show resolved Hide resolved
@MartinZikmund MartinZikmund force-pushed the dev/mazi/android-paint-reuse branch from e0efcd1 to 9e168b4 Compare September 7, 2023 10:57
@nventive-devops
Copy link
Contributor

The build 94131 found UI Test snapshots differences: android-28-net7: 0, android-28-net7-Snap: 56, ios: 32, ios-Snap: 131, skia-gtk-screenshots: 17, skia-wpf-screenshots: 12, wasm: 46, wasm-automated-net7.0-UWP-Benchmarks: 0, wasm-automated-net7.0-UWP-Default: 36, wasm-automated-net7.0-UWP-RuntimeTests: 0, wasm-automated-net7.0-WinUI-RuntimeTests: 0

Details
  • android-28-net7: 0 changed over 1

  • android-28-net7-Snap: 56 changed over 1045

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Control_BasicEnability_UITests_Shared_Windows_UI_Xaml_Enability_BasicEnability
    • Gesture_Recognizer_VisualStates_Buttons_UITests_Shared_Windows_UI_Input_VisualStatesTests_Buttons
    • Image_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Equal_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Equal
    • Image_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Wider_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Wider
    • Pointers_UITests_Windows_UI_Input_PointersTests_HitTest_Clipping_UITests_Windows_UI_Input_PointersTests_HitTest_Clipping
    • Scrolling_UITests_Windows_UI_Xaml_Controls_ScrollViewerTests_ScrollViewer_Nested_UITests_Windows_UI_Xaml_Controls_ScrollViewerTests_ScrollViewer_Nested
    • SwipeControl_MUXControlsTestApp_SwipeControlPage2_MUXControlsTestApp_SwipeControlPage2
    • Grid_Quadrant_absolute_split_Uno_UI_Samples_Content_UITests_GridTestsControl_Quadrant_absolute_split
    • ListView_ListViewScrollIntoViewSnapPoints_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewScrollIntoViewSnapPoints
    • ListView_ListViewSelectedItems_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewSelectedItems
    • NavigationView_MUXControlsTestApp_NavigationViewRS4Page_MUXControlsTestApp_NavigationViewRS4Page
    • Progress_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • TextBlock_TextBlock_Visibility_Arrange_UITests_Shared_Windows_UI_Xaml_Controls_TextBlockControl_TextBlock_Visibility_Arrange
    • Gesture_Recognizer_UITests_Shared_Windows_UI_Input_GestureRecognizerTests_HoldingTests_UITests_Shared_Windows_UI_Input_GestureRecognizerTests_HoldingTests
    • ListView_ListViewIncrementalLoading_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewIncrementalLoading
    • ListView_ListViewItem_PressedState_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewItem_PressedState
    • Scrolling_UITests_Windows_UI_Xaml_Controls_ScrollViewerTests_ScrollViewer_SnapPoints_UITests_Windows_UI_Xaml_Controls_ScrollViewerTests_ScrollViewer_SnapPoints
    • Transform_TextBox_With_RotateTransform_SamplesApp_Wasm_Windows_UI_Xaml_Media_Transform_TextBox_With_RotateTransform
    • Transform_Border_With_Off_Centre_RotateTransform_SamplesApp_Wasm_Windows_UI_Xaml_Media_Transform_Border_With_Off_Centre_RotateTransform
    • Transform_Border_With_RotateTransform_SamplesApp_Wasm_Windows_UI_Xaml_Media_Transform_Border_With_RotateTransform
  • ios: 32 changed over 270

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ProgressRing_Visibility_Collapsed_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • Screenshots_Image_Stretch_Alignment_Taller_Mode-1
    • Screenshots_Image_Stretch_Alignment_Equal_Mode-0
    • Keyboard_Textbox_NoScrollViewer_Validation_5_-_Remove_Focus_on_numberTextBox
    • Keyboard_Textbox_NoScrollViewer_Validation_0_-_Remove_Focus_on_normalTextBox
    • Screenshots_Image_Stretch_Algmnt_Inf_Vertical_Mode-2
    • Screenshots_Image_Stretch_Alignment_Wider_Mode-0
    • Screenshots_Image_Stretch_Alignment_Wider_Mode-1
    • TextBox_RoundedCorners_UITests_Shared_Windows_UI_Xaml_Controls_TextBoxTests_TextBox_RoundedCorners
    • BasicExpressionTest_UITests_Microsoft_UI_Xaml_Controls_NumberBoxTests_NumberBox_ExpressionTest
    • ListView_ObservableCollection_Creation_Count_Scrolled1
    • ProgressRing_IsEnabled_Running_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • Screenshots_Image_Stretch_Alignment_Equal_Mode-2
    • Screenshots_Image_Stretch_Alignment_Equal_Mode-3
    • Screenshots_Image_Stretch_Alignment_Bigger_Mode-2
    • Screenshots_Image_Stretch_Alignment_Taller_Mode-2
    • Screenshots_Image_Stretch_Alignment_Wider_Mode-3
    • Keyboard_Textbox_NoScrollViewer_Validation_4_-_Remove_Focus_on_multilineTextBox
    • Screenshots_Image_Stretch_Alignment_Equal_Mode-1
    • ListView_ObservableCollection_Creation_Count_Removed_above
  • ios-Snap: 131 changed over 1036

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Border_Border_Simple_No_Background_With_Content_Border_With_Background_Uno_UI_Samples_UITests_BorderTestsControl_Border_Simple_No_Background_With_Content_Border_With_Background
    • CommandBar_CommandBar_Background_UITests_Windows_UI_Xaml_Controls_CommandBar_Background_CommandBar_Background_Frame
    • Gesture_Recognizer_VisualStates_ListViewItem_UITests_Shared_Windows_UI_Input_VisualStatesTests_ListViewItem
    • Gesture_Recognizer_VisualStates_TextBox_UITests_Shared_Windows_UI_Input_VisualStatesTests_TextBox_VisualStates
    • Icons_UITests_Microsoft_UI_Xaml_Controls_ImageIconTests_ImageIconPage_UITests_Microsoft_UI_Xaml_Controls_ImageIconTests_ImageIconPage
    • ListView_ListViewGrouped_ItemContainerStyleSelector_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewGrouped_ItemContainerStyleSelector
    • LoopingSelector_UITests_Windows_UI_Xaml_Controls_LoopingSelectorTests_LoopingSelector_Items_UITests_Windows_UI_Xaml_Controls_LoopingSelectorTests_LoopingSelector_Items
    • RatingControl_UITests_Microsoft_UI_Xaml_Controls_RatingControlTests_RatingControlPage_UITests_Microsoft_UI_Xaml_Controls_RatingControlTests_RatingControlPage
    • Shapes_UITests_Windows_UI_Xaml_Shapes_Shapes_Default_StrokeThickness_UITests_Windows_UI_Xaml_Shapes_Shapes_Default_StrokeThickness
    • Buttons_UITests_Microsoft_UI_Xaml_Controls_RadioButtonsTests_RadioButtonsBasicPage_UITests_Microsoft_UI_Xaml_Controls_RadioButtonsTests_RadioButtonsBasicPage
    • ColorPicker_WinUIColorPickerPage_UITests_Shared_Microsoft_UI_Xaml_Controls_ColorPickerTests_WinUIColorPickerPage
    • ContentPresenter_ContentPresenter_LocalOverride_Uno_UI_Samples_Content_UITests_ContentPresenter_ContentPresenter_LocalOverride
    • ContentPresenter_ContentPresenter_Padding_Uno_UI_Samples_Content_UITests_ContentPresenter_ContentPresenter_Padding
    • Grid_Grid_Auto_Text_Block_Trimming_Uno_UI_Samples_Content_UITests_GridTestsControl_Grid_Auto_Text_Block_Trimming
    • Grid_Grid_ColSpan_Bottom_Uno_UI_Samples_Content_UITests_GridTestsControl_Grid_ColSpan_Bottom
    • Grid_Quadrant_uneven_split_Uno_UI_Samples_Content_UITests_GridTestsControl_Quadrant_uneven_split
    • Image_UITests_Windows_UI_Xaml_Controls_ImageTests_Image_Formats_UITests_Windows_UI_Xaml_Controls_ImageTests_Image_Formats
    • Border_Border_Corner_Overlap_UITests_Shared_Windows_UI_Xaml_Controls_BorderTests_Border_CornerOverlap
    • Brushes_UITests_Windows_UI_Xaml_Media_BrushesTests_SolidColorBrush_Color_Changed_UITests_Windows_UI_Xaml_Media_BrushesTests_SolidColorBrush_Color_Changed
    • Brushes_Uno_UI_Samples_UITests_ImageBrushTestControl_DoubleImageBrushInList_Uno_UI_Samples_UITests_ImageBrushTestControl_DoubleImageBrushInList
  • skia-gtk-screenshots: 17 changed over 1123

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ListView-ListViewSelectedItems.png
    • Progress-WindowsProgressRing_GH1220.png
    • Progress-WinUIProgressRingPage.png
    • Progress-WinUIProgressRing_CustomSources.png
    • Progress-WinUIProgressRing_Features.png
    • MUX-TabViewPage.png
    • DragAndDrop-DragDrop_TestPage.png
    • MUX-WinUIProgressRingPage.png
    • MUX-WinUIProgressRing_CustomSources.png
    • PipsPager-PipsPagerExamples.png
    • TextBlock-TextBlock_FixedWidth_With_DataBound_Run.png
    • MediaPlayerElement-Using .3gp.png
    • TextBlock-TextBoxSizeChanging.png
    • NavigationView-FluentStyle_NavigationViewSample.png
    • TextBlock-TextBlockMultilineInStarStackPanel.png
    • Progress-ProgressRingHeightTest.png
    • WinUI-PipsPagerExamples.png
  • skia-wpf-screenshots: 12 changed over 1123

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Progress-ProgressRingHeightTest.png
    • Progress-WindowsProgressRing_GH1220.png
    • PipsPager-PipsPagerExamples.png
    • TabView-TabViewPage.png
    • MUX-WinUIProgressRingPage.png
    • MUX-WinUIProgressRing_CustomSources.png
    • ListView-ListViewSelectedItems.png
    • MUX-TabViewPage.png
    • Progress-WinUIProgressRingPage.png
    • Progress-WinUIProgressRing_CustomSources.png
    • Progress-WinUIProgressRing_Features.png
    • WinUI-PipsPagerExamples.png
  • wasm: 46 changed over 1042

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • MUXControlsTestApp.NavigationViewMenuItemStretchPage
    • SamplesApp.Samples.Windows_UI_Xaml_Controls.NavigationViewTests.NavigationView_BasicNavigation
    • MUXControlsTestApp.NavigationViewBlankPage1
    • SamplesApp.Wasm.Windows_UI_Xaml_Controls.ListView.ListView_IsSelected
    • UITests.Microsoft_UI_Xaml_Controls.ColorPickerTests.ColorPickerSample
    • UITests.Microsoft_UI_Xaml_Controls.RatingControlTests.RatingControlPage
    • MUXControlsTestApp.SwipeControlPage2
    • UITests.Microsoft_UI_Xaml_Controls.ProgressRing.ProgressRingHeightTest
    • UITests.Windows_Media.MediaPlayerTests
    • MUXControlsTestApp.PipsPagerExamples
    • UITests.Microsoft_UI_Xaml_Controls.TabViewTests.TabViewPage
    • UITests.Windows_UI_Xaml_Controls.ProgressRing.WindowsProgressRing_GH1220
    • UITests.Windows_UI_Xaml_Shapes.Offscreen_Shapes
    • Uno.UI.Samples.Content.UITests.CommandBar.CommandBar_With_Long_Sentences
    • SamplesApp.Samples.Microsoft_UI_Xaml_Controls.NavigationViewTests.FluentStyle.FluentStyle_NavigationViewSample
    • UITests.Shared.Microsoft_UI_Xaml_Controls.TwoPaneViewTests.TwoPaneViewPage
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Stretch_Fill
    • initial_state
    • MUXControlsTestApp.PaneLayoutTestPage
    • UITests.Shared.Windows_UI_Xaml_Automation.AutomationProperties_Name
  • wasm-automated-net7.0-UWP-Benchmarks: 0 changed over 1

  • wasm-automated-net7.0-UWP-Default: 36 changed over 1931

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ListView_SelectedItems_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewSelectedItems
    • LoopingSelector_UITests_Windows_UI_Xaml_Controls_LoopingSelectorTests_LoopingSelector_Short_UITests_Windows_UI_Xaml_Controls_LoopingSelectorTests_LoopingSelector_Short
    • MediaPlayerElement_Using_ogg_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Ogg_Extension
    • Progress_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • ListView_ListViewSelectedItems_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewSelectedItems
    • Brushes_Uno_UI_Samples_Samples_Shared_Content_UITests_ImageBrushInList_Uno_UI_Samples_Samples_Shared_Content_UITests_ImageBrushInList
    • MediaPlayerElement_Mini_player_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Minimal
    • MediaPlayerElement_Sources_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Sources
    • MediaPlayerElement_Using_3gp_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_3gp_Extension
    • MediaPlayerElement_Using_avi_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Avi_Extension
    • MediaPlayerElement_Using_flv_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Flv_Extension
    • MediaPlayerElement_Using_mov_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Mov_Extension
    • MediaPlayerElement_Using_mp3_Audio_only_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Mp3_Extension
    • Brushes_Uno_UI_Samples_UITests_ImageBrushTestControl_Ellipse_Uno_UI_Samples_UITests_ImageBrushTestControl_Ellipse
    • MediaPlayerElement_MediaPlayerElement_Stretch_Fill_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Stretch_Fill
    • PipsPager_MUXControlsTestApp_PipsPagerExamples_MUXControlsTestApp_PipsPagerExamples
    • ColorPicker_WinUIColorPickerPage_UITests_Shared_Microsoft_UI_Xaml_Controls_ColorPickerTests_WinUIColorPickerPage
    • Default_SamplesApp_Wasm_Windows_UI_Xaml_Controls_ListView_ListView_IsSelected_SamplesApp_Wasm_Windows_UI_Xaml_Controls_ListView_ListView_IsSelected
    • When_MultipleSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • TextBlock_UITests_Windows_UI_Xaml_Controls_TextBlockControl_TextBlock_RelativeTextSize_UITests_Windows_UI_Xaml_Controls_TextBlockControl_TextBlock_RelativeTextSize
  • wasm-automated-net7.0-UWP-RuntimeTests: 0 changed over 1

  • wasm-automated-net7.0-WinUI-RuntimeTests: 0 changed over 1

@MartinZikmund MartinZikmund merged commit 81c6787 into master Sep 14, 2023
@MartinZikmund MartinZikmund deleted the dev/mazi/android-paint-reuse branch September 14, 2023 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build Categorizes an issue or PR as relevant to build infrastructure platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Android] Reuse Paint instances Border with CornerRadius is not smooth on Android
4 participants