Repository navigation
perf(grid): Index the definition collections - #24233
Conversation
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
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
foreachenumeration inGrid.ValidateDefinitionswith indexed access viaDefinitionCollectionBase.Count/GetItem(int). - Remove the now-dead
GetItems()member fromDefinitionCollectionBaseand 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.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24233/wasm-skia-net9/index.html |
|
The build 230531 found UI Test snapshots differences: Details
|
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
0c3f5e3 to
db7973e
Compare
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24233/wasm-skia-net9/index.html |
|
The build 231011 found UI Test snapshots differences: Details
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24233/wasm-skia-net9/index.html |
|
The build 231675 found UI Test snapshots differences: Details
|
|
@Mergifyio backport servicing/6.8 release/stable/6.7 |
✅ Backports have been createdDetails
|
…r-24233 perf(grid): Index the definition collections (backport #24233)
…6.7/pr-24233 perf(grid): Index the definition collections (backport #24233)
GitHub Issue: closes #24224
PR Type:
🔄 Refactoring (no functional changes, no api changes)
What changed? 🚀
ValidateDefinitionsiterateddefinitions.GetItems(), which hands back the backingDependencyObjectCollectionasIEnumerable<DefinitionBase>. ItsGetEnumeratorreturnsIEnumerator<T>, boxing theList<T>.Enumeratorstruct, and the method runs twice perGridmeasure — once for rows, once for columns.Loop by index instead.
DefinitionCollectionBasealready exposedCountandGetItem(int), andGetItemis_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 📊
grid.full-passgrid.full-passgrid.full-passWorkload 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 inVisualTreeHelper.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 ✅
Screenshots Compare Test Runresults. — to check once CI has run