Skip to content

perf(dp): Inline storage for small DependencyObjectCollections - #26587

Open
MartinZikmund wants to merge 2 commits into
masterfrom
dev/mazi/perf2026-docollection
Open

MartinZikmund wants to merge 2 commits into
masterfrom
dev/mazi/perf2026-docollection

Conversation

@MartinZikmund

@MartinZikmund MartinZikmund commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

GitHub Issue: Part of #24093

PR Type:

🔄 Refactoring

What changed? 🚀

Split out of #24094 (originally by @morning4coffe-dev), which now only carries the opt-in XamlOptionalChanges part. This piece is always on, so it gets its own review.

DependencyObjectCollection<T> stores up to two items inline (C# InlineArray) and allocates a List<T> only for the third. WinUI measured 82.68% of DO collections at size 0–2 and made the same change in f235521a.

  • Enumeration stays allocation-free and versioned. Reentrancy and event semantics are unchanged; as with List<T>, replacing an item through the indexer doesn't invalidate in-flight enumerators.
  • Drops the collection's self-subscribed event delegate and creates external handler state lazily.
  • ReplaceRange is rebuilt on the inline storage. Row/ColumnDefinition, Inline, Timeline and VisualStateGroup collections follow the new API.

Validation

  • Compile: Uno.UI.UnitTests (net11.0).
  • Runtime: Given_DependencyObjectCollection*, 78/78.

Performance

Headless Skia app with Fluent resources (x64, net10.0, DOTNET_TieredCompilation=0), one process per scenario, 4 interleaved A/B rounds against master. Allocations are UI-thread bytes and exact: a master-vs-master null run drifted 0.00%. A time change is bold only when it is larger than that scenario's null drift and the A/B ranges don't overlap; anything else is marked noise. Background load on the machine made some timings noisy.

Scenario Allocated per iteration Δ alloc Per unit Time per iteration (median) Δ time Null drift
2,000 Grids with 2 rows + 1 column 10,528,000 → 9,984,000 B −5.17% −272 B 3.41 → 2.89 ms −15.3% ±3.4%
Mixed page: 40 × 7 Fluent controls 90,441,326 → 89,653,540 B −0.87% −2.7 KB 282.24 → 278.72 ms −1.3% (noise) ±3.1%
300 Fluent Buttons, built + laid out 34,689,532 → 34,531,132 B −0.46% −528 B 88.75 → 91.40 ms +3.0% (noise) ±6.8%
100 Button/CheckBox × 4 visual-state changes 745,659 → 779,659 B +4.56% +85 B 1.96 → 2.61 ms +32.9% (noise) ±7.7%
200k Tag set/get 0 → 0 B 0 — 19.03 → 19.53 ms +2.7% (noise) ±6.1%

Small collections save 272 B per Grid with two rows and one column (−5%, 15% faster), and about 2.7 KB per control on the mixed page.

Warning

Open regression: visual-state changes allocate +85 B per state change (+4.6%), exactly reproducible across all rounds. A sampled allocation trace points at extra boxed collection enumerators on the setter/storyboard paths of VisualStateGroup.GoToState, but the call counts through the public GetEnumerator are identical to master, so the root cause isn't pinned yet. This should be resolved before merging.

PR Checklist ✅

🤖 Generated with Claude Code

https://claude.ai/code/session_01TXMNu1LMuUpziGZWHVDmpX

Copilot AI balanced review requested due to automatic review settings November 18, 2026 10:55

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@mergify

mergify Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 24s —— View job


Review of #26587: inline storage for DependencyObjectCollection<T>

Verdict: ship. I found no blocking issues. This is a review by inspection only. I did not build or run tests in this job, so the PR's own validation (78/78 runtime tests) is the only runtime evidence.

Severity counts: 0 blocking, 0 major, 2 minor nits (below). No inline comments were needed.

What I checked

  • Storage transitions: insert, remove, range operations and Clear are consistent between the inline and spilled paths. Spill() clears the inline slots, and _count and _version are updated on every structural mutation.
  • Versioning: DependencyObjectItems still fails on a mid-walk mutation, because it checks ItemsVersion.
  • Callers: no leftover uses of IndexedItems, InnerList or .Items remain in src/Uno.UI. Grid, Inline, Timeline and VisualStateGroup all moved to GetEnumeratorFast().
  • Event ordering: OnCollectionChanged() now runs before the external handlers, as the removed self-subscription used to. It also runs before the early return when no handlers are registered.
  • Style: the new code follows AGENTS.md (braces, tabs, no event Action). I found no [Ignore] or Inconclusive in the new tests, and no platform-suffix issues.

Minor nits (non-blocking)

  1. RaiseVectorChanged reads _vectorChangedHandlers is null outside the lock, while add and remove mutate it under the lock. The race is benign because the field only goes from null to non-null. A short comment saying so, or a Volatile.Read, would make that explicit.
  2. The collection never returns to inline storage after spilling, even after Clear(). That is fine for the 0–2 item case this targets, and the doc comment already says so. If you want, the Clear() path could drop _spilledItems once the list is empty, to release memory for collections that grow and then shrink.

Cross-cutting

  • The Conventional Commit title is fine.
  • The "Docs" and "Screenshots Compare" checklist items are unchecked. Neither looks applicable to this internal refactor, but wait for the screenshot compare run before merging, since Grid and VisualStateGroup are on hot UI paths.

@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label Nov 18, 2026
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 247321 found UI Test snapshots differences: skia-linux-screenshots: 460, skia-windows-screenshots: 470

Details
  • skia-linux-screenshots: 460 changed over 2500

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png
    • AnimatedBackVisualSourceSamplePage.png
    • Basics.png-dark
    • Basics.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • CheckBox_DisabledInDisabledListView.png-dark
    • CheckBox_DisabledInDisabledListView.png
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • Accessibility_Showcase.png-dark
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
  • skia-windows-screenshots: 470 changed over 2500

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png-dark
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • ColorPickerSample.png-dark
    • ColorPickerSample.png
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • Accessibility_ScreenReader.png-dark
    • Basics.png-dark
    • Basics.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • CheckBox_DisabledInDisabledListView.png-dark
    • CheckBox_DisabledInDisabledListView.png
    • AnimatedBackVisualSourceSamplePage.png
    • AutomationProperties_StructureAndProps.png-dark
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants