Skip to content

perf(grid): Stop leaking the pooled span store on the empty path - #24229

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

MartinZikmund merged 1 commit into
masterfrom
dev/mazi/perf-grid-spanstore

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #24220

PR Type:

🐞 Bugfix

What changed? 🚀

SpanStoreStackVector rents from ArrayPool<T>.Shared in its constructor and returns the array in Dispose(). MeasureCellsGroup constructed it before the cellsHead >= cellCount early return, so that path never gave the array back. Grid.MeasureOverride calls MeasureCellsGroup up to seven times per measure and empty groups are the common case, so a typical grid leaked two to three rentals per measure while returning one: the pool bucket drains and every subsequent rent allocates.

Move the early return above the construction — nothing touches the vector before that point, so the change is inert other than not renting.

Measured impact 📊

Workload Metric Before After Δ
grid.full-pass alloc / pass 390,105 B 79,113 B −79.7 %
grid.full-pass alloc / element 285.8 B 58.0 B −79.7 %
grid.full-pass time / pass 3.67 ms 3.11 ms −15.3 %

Isolated by reverting and re-applying this change alone on the current tree, both runs executing the workload alone. Allocation figures are byte-identical across runs. The saving is exactly the leaked rentals: ~3 per grid per pass × 341 grids × a 16-element SpanStoreEntry[].

Workaround 🛠️

None available from application code.

Validation ✅

Runtime tests, Skia Desktop, Given_Grid + Given_GridLayouting + Given_GridView_Items: 85 run, 81 passed, 4 skipped, 4 failed. All 4 failures reproduce on the baseline and on the tree before any of this work, verified by two separate rebuild-and-rerun cycles.

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 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 fixes a performance bug in Grid.MeasureCellsGroup where an ArrayPool<T>-rented backing array (via SpanStoreStackVector) could be leaked on the empty-group early-return path, causing pool bucket drain and downstream allocations during repeated grid measure passes.

Changes:

  • Moves SpanStoreStackVector construction to occur after the cellsHead >= cellCount early return, preventing pool rentals on the empty path.
  • Adds a clarifying comment explaining why the construction must not precede an exit path.

💡 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 230527 found UI Test snapshots differences: skia-linux-screenshots: 73, skia-windows-screenshots: 225

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

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • DropDownButtonPage.png-dark
    • Attributed_text_FontSize_Changing.png
    • Buttons.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • ContextRequested.png-dark
    • DynamicFont.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Examples.png
    • Focus_FocusVisual_Properties.png-dark
    • ImageBrushInList.png-dark
    • ImageBrushInList.png
    • Image_Margin_Large.png
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
  • skia-windows-screenshots: 225 changed over 2368

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Battery.png-dark
    • DisplayInformation.png-dark
    • Gamepad_CurrentReading.png-dark
    • Gamepad_Enumeration.png-dark
    • Gamepad_Enumeration.png
    • ImageSourceUrlMsAppDataScheme.png-dark
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • Contacts_Pick.png-dark
    • Contacts_Pick.png
    • ContentPresenter_Template.png-dark
    • ContentPresenter_Template.png
    • DataTransferManager.png-dark
    • DataTransferManager.png
    • Examples.png
    • Battery.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Clipping652.png-dark
    • Clipping652.png

SpanStoreStackVector rents from ArrayPool<T>.Shared in its constructor
and returns the array in Dispose(). MeasureCellsGroup constructed it
before the cellsHead >= cellCount early return, so that path never gave
the array back. Grid.MeasureOverride calls MeasureCellsGroup up to seven
times per measure and empty groups are the common case, so a typical
grid leaked two to three rentals per measure while returning one: the
pool bucket drains and every subsequent rent allocates.

Move the early return above the construction; nothing touches the vector
before that point.

Measured on a 341-Grid tree (specs/059-performance-improvements): a full
dirty layout pass drops from 3.73 ms to 1.32 ms (-65%) and from 431 KB to
120 KB of allocations (-72%). The 311 KB saved is ~1023 leaked rentals of
a 16-element SpanStoreEntry[], matching the leak one for one.

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-grid-spanstore branch from 375f343 to f3f33bc Compare August 29, 2026 10:11
@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.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 231007 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) 🚨🚨
    • DropDownButtonPage.png-dark
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • ContextRequested.png-dark
    • ContentControl_Inheritance.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • ImageBrush_Stretch.png
    • Attributed_text_FontSize_Changing.png
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • Focus_FocusVisual_Properties.png-dark
    • ImageBrushInList.png-dark
    • ImageBrushInList.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • Examples.png
  • skia-windows-screenshots: 218 changed over 2368

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • BitmapImage_vs_SvgImageSource.png
    • Dopes.png-dark
    • Grid_in_Canvas.png-dark
    • Grid_in_Canvas.png
    • Attributed_text_FontSize_Changing.png
    • DataTransferManager.png-dark
    • DataTransferManager.png
    • Attributed_text_FontSize_Changing.png-dark
    • BitmapImage_vs_SvgImageSource.png-dark
    • ClipboardTests.png-dark
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • EllipseAlignment2542_2547.png-dark
    • EllipseAlignment2542_2547.png
    • Focus_FocusState.png-dark
    • Focus_FocusState.png
    • ImageAlignment2541.png-dark
    • Hyperlink_Disabled.png-dark
    • ImageAlignment2541.png
    • Hyperlink_Disabled.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 231679 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) 🚨🚨
    • DisplayInformation.png-dark
    • Examples.png-dark
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • Buttons.png-dark
    • Buttons.png
    • Focus_FocusVisual_Properties.png-dark
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ContextRequested.png-dark
    • ContextRequested.png
    • ClipboardTests.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • Gamepad_CurrentReading.png-dark
  • skia-windows-screenshots: 2310 changed over 2402

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AndroidWindowInsets.png-dark
    • ApplicationViewSpanningRectsPage.png-dark
    • AppWindowPresenters.png
    • Attributed_text_Simple.png
    • AutoBorderStretchwithbottommargin.png
    • AutoSizedPathCentered.png
    • AutoSuggestBox_Reason.png
    • BasicEnability.png
    • BitmapIcon_Generic.png-dark
    • BitmapIcon_Generic.png
    • BorderRightwithmargins.png
    • BorderTopwithmargins.png-dark
    • Border_CornerRadius_Alignments.png-dark
    • Border_CornerRadius_Alignments.png
    • Border_Simple_No_Background_With_Content_Border_With_Background.png-dark
    • Border_Simple_No_Background_With_Content_Border_With_Background.png
    • Border_With_RotateTransform.png-dark
    • Border_With_RotateTransform.png
    • Button_IsEnabled_Automated.png
    • Button_Opacity_Automated.png-dark
  • wasm: 11 changed over 1076

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

@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 192e684 into master Sep 6, 2026
46 of 47 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/perf-grid-spanstore branch September 6, 2026 08:43
@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-24229

perf(grid): Stop leaking the pooled span store on the empty path
 (backport #24229)
agneszitte added a commit that referenced this pull request Oct 27, 2026
…6.7/pr-24229

perf(grid): Stop leaking the pooled span store on the empty path
 (backport #24229)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Grid.MeasureCellsGroup leaks its pooled span-store array on the empty-group path

6 participants