Skip to content

perf(grid): Index the definition collections - #24233

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

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

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #24224

PR Type:

🔄 Refactoring (no functional changes, no api changes)

What changed? 🚀

ValidateDefinitions iterated definitions.GetItems(), which hands back the backing DependencyObjectCollection as IEnumerable<DefinitionBase>. Its GetEnumerator returns IEnumerator<T>, boxing the List<T>.Enumerator struct, and the method runs twice per Grid measure — once for rows, once for columns.

Loop by index instead. DefinitionCollectionBase already exposed Count and GetItem(int), and GetItem is _inner[index] — the same sequence the enumerator walks — so no new API was needed. GetItems() then had no callers left and is removed rather than left dead.

Measured impact 📊

Workload Metric Before After Δ
grid.full-pass alloc / pass 79,113 B 51,833 B −34.5 %
grid.full-pass alloc / element 58.0 B 38.0 B −34.5 %
grid.full-pass time / pass 3.11 ms 3.08 ms ±0 (noise)

Workload run alone in both configurations, change reverted and re-applied on the current tree, 5 runs each, median. Allocation figures byte-identical across runs.

27,280 B saved over 341 grids = 80 B per grid per pass — two boxed List<T>.Enumerators at 40 B each, one for rows and one for columns, matching the constant measured independently in VisualTreeHelper.

Validation ✅

Runtime tests, Skia Desktop — same 937-test layout/rendering/framework suite as the visual-tree PR, 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 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 optimizes Grid.ValidateDefinitions by avoiding enumeration over the definitions collections (which can box enumerators) and instead iterating by index, reducing per-measure allocations without changing behavior or public APIs.

Changes:

  • Replace foreach enumeration in Grid.ValidateDefinitions with indexed access via DefinitionCollectionBase.Count/GetItem(int).
  • Remove the now-dead GetItems() member from DefinitionCollectionBase and its implementations in row/column definition collections.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/Uno.UI/UI/Xaml/Controls/Grid/Grid.cs Switch definition validation loop to indexed iteration to avoid boxing allocations.
src/Uno.UI/UI/Xaml/Controls/Grid/DefinitionCollectionBase.cs Remove GetItems() from the interface (no longer needed).
src/Uno.UI/UI/Xaml/Controls/Grid/RowDefinitionCollection.cs Remove explicit GetItems() implementation after interface change.
src/Uno.UI/UI/Xaml/Controls/Grid/ColumnDefinitionCollection.cs Remove explicit GetItems() implementation after interface change.

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

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

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ContentControl_Inheritance.png
    • Buttons.png
    • ContextRequested.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Focus_FocusVisual_Properties.png-dark
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • ImageBrushInList.png-dark
    • ImageBrushInList.png
    • ImageBrush_Stretch.png
    • ImageIconPage.png-dark
    • ImageIconPage.png
    • Attributed_text_FontSize_Changing.png
    • CalendarView_Theming.png-dark
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • Image_Margin_Large.png
    • ButtonClippingTestsControl.png-dark
  • skia-windows-screenshots: 242 changed over 2368

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Basics Pivot Test.png
    • Buttons.png-dark
    • Buttons.png
    • FocusManagerTest.png-dark
    • FocusManagerTest.png
    • Attributed_text_FontSize_Changing.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ContentPresenter_Template.png-dark
    • ContentPresenter_Template.png
    • Dopes.png-dark
    • Grid_def_MinMaxValues.png-dark
    • Grid_def_MinMaxValues.png
    • BitmapImage_vs_SvgImageSource.png-dark
    • ExpanderColorValidationPage.png-dark
    • Focus_FocusState.png-dark
    • Focus_FocusState.png
    • Grid_ScrollViewer.png-dark
    • Grid_ScrollViewer.png
    • Attributed_text_FontSize_Changing.png-dark

ValidateDefinitions iterated definitions.GetItems(), which hands back the
backing DependencyObjectCollection as IEnumerable<DefinitionBase>. Its
GetEnumerator returns IEnumerator<T>, boxing the List<T>.Enumerator
struct, and the method runs twice per Grid measure -- once for rows, once
for columns.

Loop by index instead. DefinitionCollectionBase already exposed Count and
GetItem(int), and GetItem is _inner[index], the same sequence the
enumerator walks, so no new API was needed. GetItems() had exactly one
caller and is removed rather than left dead.

Measured (specs/059-performance-improvements): a grid layout pass drops
34.5% of its allocations, and the 27,280 B saved is exactly 80 B per grid
-- two boxed List<T>.Enumerators, matching the 40 B constant measured
independently in the visual-tree accessors. Time is unchanged. 937 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-grid-definitions branch from 0c3f5e3 to db7973e Compare August 29, 2026 10:12
@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 231011 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) 🚨🚨
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • Focus_FocusVisual_Properties.png-dark
    • CalendarView_Theming.png-dark
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • ContentControl_Inheritance.png
    • Examples.png
    • Attributed_text_FontSize_Changing.png
    • Buttons.png
    • ImageIconPage.png-dark
    • ImageIconPage.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • ImageBrush_Stretch.png
    • DropDownButtonPage.png-dark
    • DynamicFont.png
    • Gamepad_CurrentReading.png-dark
  • skia-windows-screenshots: 225 changed over 2368

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ChatBox.png-dark
    • ChatBox.png
    • EllipsemaskingEllipseGrid.png-dark
    • ContentPresenter_NativeEmbedding_Android_FillType.png
    • Grid_in_Canvas.png-dark
    • Grid_in_Canvas.png
    • Attributed_text_FontSize_Changing.png
    • Focus_FocusState.png-dark
    • Focus_FocusState.png
    • Hyperlink_Disabled.png-dark
    • Hyperlink_Disabled.png
    • DisplayInformation.png-dark
    • Dopes.png-dark
    • ImageBrush_Formats.png-dark
    • ImageBrush_Formats.png
    • Attributed_text_FontSize_Changing.png-dark
    • AppWindowPresenters.png-dark
    • BitmapImage_vs_SvgImageSource.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.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 231675 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) 🚨🚨
    • ContextRequested.png-dark
    • ContextRequested.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • DisplayInformation.png-dark
    • CalendarView_Theming.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • Gamepad_Enumeration.png
    • Examples.png-dark
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • ImageIconPage.png-dark
    • Buttons.png-dark
    • Buttons.png
  • skia-windows-screenshots: 2310 changed over 2402

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ApplicationViewMode.png
    • AppBarButtonWithIconTest.png-dark
    • AppWindowFeatures.png
    • AutomationProperties_AutomationId.png-dark
    • AppWindowTitleBar Properties.png
    • AutoSuggestBox_Icons.png-dark
    • AppXamlDefinedResources.png
    • BasicAutoSuggestBox.png
    • AuthenticationBroker_Demo.png
    • BasicThemeResources.png
    • AutoSizedPathCentered.png
    • BitmapIcon_Monochromatic.png
    • BasicAcrylicBrushTest2.png
    • BorderLeftwithmargins.png
    • Border_CornerRadius.png
    • BorderTopwithmargins.png
    • Border_CornerRadius_Clipping2.png
    • Border_CornerRadius_Alignments.png-dark
    • Border_CornerRadius_Gradient.png-dark
    • Border_CornerRadius_Alignments.png
  • wasm: 11 changed over 1076

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

@MartinZikmund
MartinZikmund merged commit fef1d4a into master Sep 6, 2026
46 of 47 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/perf-grid-definitions branch September 6, 2026 06:47
@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-24233

perf(grid): Index the definition collections
 (backport #24233)
agneszitte added a commit that referenced this pull request Oct 27, 2026
…6.7/pr-24233

perf(grid): Index the definition collections
 (backport #24233)
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.ValidateDefinitions boxes a collection enumerator twice per measure

6 participants