Skip to content

perf(composition): Walk shapes by index on the frame path - #24231

Merged
MartinZikmund merged 1 commit into
masterfrom
dev/mazi/perf-shapevisual-linq
Sep 6, 2026
Merged

MartinZikmund merged 1 commit into
masterfrom
dev/mazi/perf-shapevisual-linq

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #24222

PR Type:

🔄 Refactoring (no functional changes, no api changes)

What changed? 🚀

RequiresRepaintOnEveryFrame, DamageRegionSamplingMargin and CanPaint() are queried once per shape element per frame, and each was a LINQ chain — so every frame allocated a collection enumerator, one or two iterators and a closure per shape visual. BorderVisual already implements the equivalent members as plain expressions.

Walk the collection by index instead. DamageRegionSamplingMargin keeps a seen flag so DefaultIfEmpty(0f) semantics are preserved exactly: 0 is returned when there is no sprite shape at all, rather than clamping a set of margins up to 0, which a naive Max starting from 0 would do.

Measured impact 📊

Workload Metric Before After Δ
render.full-paint alloc / frame 381,830 B 271,826 B −28.8 %
render.full-paint alloc / element / frame 244.6 B 174.1 B −28.8 %
render.full-paint time / frame 70.08 ms 69.28 ms −1.1 % (noise)

Same 1,561-element rounded tree, paint only, 5 runs each, median. Allocation figures vary by <5 B across runs. Measured on a tree that already has the RectangleClip cache applied.

Validation ✅

Same suite as the clip-path PR (Given_Border, Given_ContainerVisual, Given_ShapeVisual, Given_Visual_Damage, Given_UIElement, Windows_UI_Xaml_Shapes.*): 671 run, 654 passed, 16 failed, set-compared against a baseline build — 0 new failures, 0 newly passing.

PR Checklist ✅

  • 🧪 Added Runtime tests, UI tests, or a manual test sample (for bug fixes / features, if applicable)
  • 📚 Docs have been added/updated following the documentation template (for bug fixes / features) — n/a, no API or behaviour change for app authors
  • 🖼️ Validated PR Screenshots Compare Test Run results. — to check once CI has run
  • ❗ Contains NO breaking changes
  • 👀 Reviewed 2 other open pull requests (optional but appreciated!)

Copilot AI lite review requested due to automatic review settings August 27, 2026 07:19
@github-actions github-actions Bot added the area/skia ✏️ Categorizes an issue or PR as relevant to Skia label Aug 27, 2026
@github-actions

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 0s —— View job


I'll analyze this and get back to you.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses #24222 by removing per-frame LINQ allocations in ShapeVisual’s Skia implementation, replacing iterator-based queries with index-based loops while preserving existing semantics (including the DefaultIfEmpty(0f) behavior for DamageRegionSamplingMargin).

Changes:

  • Replaced LINQ-based RequiresRepaintOnEveryFrame evaluation with an index-based scan over shapes.
  • Reimplemented DamageRegionSamplingMargin as an index-based max scan with a seen flag to preserve empty-sequence semantics.
  • Replaced LINQ-based CanPaint() shape scan with an index-based loop and early-return pattern.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 230529 found UI Test snapshots differences: skia-linux-screenshots: 73, skia-windows-screenshots: 235

Details
  • skia-linux-screenshots: 73 changed over 2366

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ContextRequested.png-dark
    • Buttons.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ImageBrushInList.png-dark
    • ImageBrushInList.png
    • CalendarView_Theming.png-dark
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • ImageBrush_Stretch.png
    • ImageIconPage.png-dark
    • ImageIconPage.png
    • Attributed_text_FontSize_Changing.png
    • DynamicFont.png
    • Examples.png
    • ContentControl_Inheritance.png
    • DropDownButtonPage.png-dark
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
  • skia-windows-screenshots: 235 changed over 2368

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • BitmapImage_vs_SvgImageSource.png-dark
    • BitmapImage_vs_SvgImageSource.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • FocusManagerTest.png-dark
    • FocusManagerTest.png
    • Hyperlink_Disabled.png-dark
    • Hyperlink_Disabled.png
    • ContentPresenter_NativeEmbedding_ZIndex.png
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • Focus_FocusState.png-dark
    • Focus_FocusState.png
    • HyperlinkButton_IsEnabled_Automated.png-dark
    • HyperlinkButton_IsEnabled_Automated.png
    • ImagesInlineInFlipView.png-dark
    • ImagesInlineInFlipView.png
    • Image_UseTargetSize.png-dark

RequiresRepaintOnEveryFrame, DamageRegionSamplingMargin and CanPaint are
queried once per shape element per frame, and each was a LINQ chain, so
every frame allocated a collection enumerator, one or two iterators and a
closure per shape visual. BorderVisual already implements the same two
members as plain expressions.

Walk the collection by index instead. DamageRegionSamplingMargin keeps a
`seen` flag so DefaultIfEmpty(0f) semantics are preserved exactly: 0 is
returned when there is no sprite shape at all, rather than clamping a set
of margins up to 0.

Measured on the same 1561-element rounded tree
(specs/059-performance-improvements): paint allocations drop from 382 KB
to 272 KB per frame (-29%), and to -48% cumulatively against the tree
before the clip-path fix. Rendering runtime tests: identical pass/fail
sets, 0 new failures.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015DSdL5YzLhjx8CeGXZf1Au
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/perf-shapevisual-linq branch from 7f38d2f to b0e17dd Compare August 29, 2026 10:12
@unodevops

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 0s —— View job


I'll analyze this and get back to you.

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 231009 found UI Test snapshots differences: skia-linux-screenshots: 73, skia-windows-screenshots: 218

Details
  • skia-linux-screenshots: 73 changed over 2366

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Focus_FocusVisual_Properties.png-dark
    • CalendarView_Theming.png-dark
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • Attributed_text_FontSize_Changing.png
    • Examples.png
    • Buttons.png
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Image_Margin_Large.png
    • DropDownButtonPage.png-dark
    • ImageBrush_Stretch.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ContentControl_Inheritance.png
    • ContextRequested.png-dark
    • DynamicFont.png
    • Gamepad_CurrentReading.png-dark
  • skia-windows-screenshots: 218 changed over 2368

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • Attributed_text_FontSize_Changing.png
    • Basics Pivot Test.png-dark
    • BitmapImage_vs_SvgImageSource.png
    • FocusManagerTest.png-dark
    • FocusManagerTest.png
    • Grid_with_MinWidthColumns.png-dark
    • Grid_with_MinWidthColumns.png
    • EllipseAlignment2542_2547.png-dark
    • EllipseAlignment2542_2547.png
    • EllipsemaskingEllipseGrid.png
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_Enumeration.png-dark
    • Grid_def_MinMaxValues.png-dark
    • Grid_def_MinMaxValues.png
    • ImageAlignment2541.png-dark
    • ImageAlignment2541.png

@MartinZikmund
MartinZikmund changed the base branch from feature/breakingchanges to master September 2, 2026 20:01
@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 231677 found UI Test snapshots differences: skia-linux-screenshots: 57, skia-windows-screenshots: 2310, wasm: 11

Details
  • skia-linux-screenshots: 57 changed over 2348

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • Focus_FocusVisual_Properties.png-dark
    • ImageIconPage.png-dark
    • Buttons.png-dark
    • Buttons.png
    • DisplayInformation.png-dark
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • Gamepad_Enumeration.png
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • ContextRequested.png-dark
    • ContextRequested.png
    • Examples.png-dark
    • Examples.png
    • ExpanderColorValidationPage.png-dark
  • skia-windows-screenshots: 2310 changed over 2402

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png
    • AndroidWindowInsets.png-dark
    • AppBarButtonWithIconTest.png-dark
    • AppBarButtonTest.png
    • ApplicationViewMode.png
    • ApplicationViewSpanningRectsPage.png-dark
    • AppWindowPresenters.png
    • AuthenticationBroker_Demo.png
    • Attributed_text_Simple.png-dark
    • AutoSizedPathCentered.png-dark
    • AutoBorderStretchwithtopmargin.png-dark
    • AutoSuggestBox_SoftKeboard.png
    • AutoSuggestBox_Keyboard.png
    • BasicThemeResources.png-dark
    • BasicEnability.png-dark
    • BitmapIcon_Foreground.png
    • BeginTime_MultipleAnimations.png-dark
    • Border_BorderThickness.png-dark
    • BeginTime_MultipleAnimations.png
    • Border_BorderThickness.png
  • wasm: 11 changed over 1076

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • UITests.Uno_Web.Http.CookieManagerTests
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Minimal
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • UITests.Windows_UI_Xaml_Controls.CalendarView.CalendarView_Theming
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewSelectedItems
    • SamplesApp.Wasm.Windows_UI_Xaml_Controls.ListView.ListView_IsSelected
    • UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.WinUIExpanderPage
    • Uno.UI.Samples.Content.UITests.WebView.WebView_AnchorNavigation
    • UITests.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_NavigationProperties
    • SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_EnableDevTools
    • UITests.Windows_UI_Xaml_Media_Animation.ColorAnimation_Background

@mergify

mergify Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@MartinZikmund
MartinZikmund merged commit d5e8b93 into master Sep 6, 2026
46 of 47 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/perf-shapevisual-linq branch September 6, 2026 06:48
@agneszitte

Copy link
Copy Markdown
Member

@Mergifyio backport servicing/6.8 release/stable/6.7

@mergify

mergify Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

backport servicing/6.8 release/stable/6.7

✅ Backports have been created

Details

agneszitte added a commit that referenced this pull request Oct 27, 2026
…r-24231

perf(composition): Walk shapes by index on the frame path
 (backport #24231)
agneszitte added a commit that referenced this pull request Oct 27, 2026
…6.7/pr-24231

perf(composition): Walk shapes by index on the frame path
 (backport #24231)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/skia ✏️ Categorizes an issue or PR as relevant to Skia

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Skia] ShapeVisual runs three LINQ chains per frame

6 participants