Skip to content

perf: Size DependencyProperty storage to the properties set - #25047

Merged
ajpinedam merged 4 commits into
masterfrom
dev/mazi/perf-dp-details-exact-size
Oct 27, 2026
Merged

ajpinedam merged 4 commits into
masterfrom
dev/mazi/perf-dp-details-exact-size

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #24754

PR Type:

🐞 Bugfix

What changed? 🚀

DependencyPropertyDetailsCollection stored property details in 16-slot buckets (plus an offsets array) rented from shared pools. Since the DependencyObject finalizer and disposal path were removed (#23703), an element's final arrays are never returned, so pools only recycle outgrown arrays and every element ends up allocating fresh, mostly empty 16- or 32-slot arrays (~+290 B per Border vs 6.7).

This replaces the buckets, the offsets array and both pools with a small open-addressed table keyed by DependencyProperty.UniqueId. It starts at 4 slots and stays at most half full; lookups stay O(1). The unreachable Dispose is removed. This also removes a latent bug where a GetAllDetails() walk adding a property returned the old array to the pool (cleared, rentable by another element) while it was still being read.

Measured, bytes allocated per creation:

Type Before After
Border 3,320 3,032
Grid 3,528 3,241
TextBlock 5,473 5,184
Button 5,896 5,608
7 properties with ids up to ~3000 1,651 816

GetValue speed is unchanged within noise (unset 5.59 → 5.49 ns, set 7.87 → 7.46 ns, alternating builds, best of 5).

Tests: Given_DependencyPropertyDetailsCollection (unit tests): high-id property, fresh Border slot count and new Border() allocation fail on master and pass now; collision/growth tests added. Full unit suite (4,258) shows no new failures (12 When_Gregorian_FixedDate* fail on both builds, timezone-related).

Note: GetAllDetails() iteration order changes (enter/leave and theme walks follow it). Nothing found that depends on the order; CI runtime tests will confirm.

PR Checklist ✅

🤖 Generated with Claude Code

https://claude.ai/code/session_01NL1zD4nmcDjrcPhceNXFNm

Copilot AI balanced review requested due to automatic review settings October 6, 2026 11:01

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 reached their quota limit.

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

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

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


Review of #25047

Verdict: ship, pending CI runtime tests.

Issues: 0 high, 0 medium, 1 low (inline).

Summary

  • The open-addressed table is correct. The capacity is always a power of two, and load stays at or below 50%, so probing always ends at an empty slot. The shared 1-slot _noEntries array is safe because the first Add always grows it.
  • Dispose removal is safe. Nothing outside the collection referenced it, and it fixes the pooled-array reuse hazard during GetAllDetails walks.
  • This is a root-cause fix for the allocation overhead. It removes the pools rather than tuning them.
  • Tests are in place: unit tests cover high ids, collisions and growth, and the PR states they fail on master.
  • I did not build or run anything. This is a code review by inspection only.
  • The remaining risk is iteration-order changes in the enter/leave and theme walks. Please check the CI runtime test results.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 237637 found UI Test snapshots differences: skia-linux-screenshots: 130, skia-windows-screenshots: 178

Details
  • skia-linux-screenshots: 130 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • CalendarView_Theming.png-dark
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png
    • ColorPickerSample.png-dark
    • ColorPickerSample.png
    • CompositionPath.png-dark
    • CompositionPath.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • ButtonClippingTestsControl.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • ClipboardTests.png-dark
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_Enumeration.png-dark
  • skia-windows-screenshots: 178 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • Examples.png
    • DisplayInformation.png-dark
    • Grid_Multi_Column_Span.png-dark
    • Grid_Multi_Column_Span.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • Grid_InsideStackPanel_InsideButton.png-dark
    • Grid_InsideStackPanel_InsideButton.png
    • Grid_in_Canvas.png-dark

Copilot AI balanced review requested due to automatic review settings October 9, 2026 21:28

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 reached their quota limit.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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


Re-review of #25047 (after 7da6d0ea)

Verdict: ship, pending CI.

Issues: 0 high, 0 medium, 0 low.

  • The earlier low note is addressed. GetAllDetails now documents hash order and snapshot semantics (DependencyPropertyDetailsCollection.cs:182).
  • Code review by inspection: the open-addressed table holds up.
    • Capacity is always a power of two, and load stays at or below 50%, so probing always reaches an empty slot.
    • Grow and Add rehash correctly.
    • The shared _noEntries array is never written, because the first Add grows it.
    • CloneToForHotReload iterates _entries and tolerates null slots.
  • Not verified: I did not build or run anything, so there is no compile or runtime validation from me.
  • The screenshot diffs reported by the Azure build (130 on Linux, 178 on Windows) are not explained by this change as far as I can tell. They are the main open item. Please compare them with the baseline from master to see whether they also appear there. If they are new, GetAllDetails() order is the likely cause, through the enter/leave and theme walks.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 238683 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 174

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • DropDownButtonPage.png-dark
    • Examples.png
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • ImageBrushAlignmentXY.png-dark
    • ImageBrushAlignmentXY.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • DynamicFont.png-dark
  • skia-windows-screenshots: 174 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • ColorPickerSample.png-dark
    • ColorPickerSample.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • Grid_ColSpan_Bottom.png-dark
    • Grid_ColSpan_Bottom.png
    • Grid_DataBound_ColumnRow_Definitions.png-dark
    • Grid_DataBound_ColumnRow_Definitions.png
    • Grid_def_MinMaxValues.png-dark
    • Grid_def_MinMaxValues.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_Enumeration.png-dark
    • GridWithColumnSpan.png-dark
    • GridWithColumnSpan.png
    • Grid_Auto_Center_Cell.png-dark

Copilot AI balanced review requested due to automatic review settings October 10, 2026 22:04

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 reached their quota limit.

@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

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


Re-review of #25047 (head 1a077d43)

Verdict: ship, pending the screenshot comparison.

Issues: 0 high, 0 medium, 0 low.

  • Method: code review by inspection only. I did not build or run anything, so there is no compile or runtime validation from me.
  • Table correctness: DependencyProperty.UniqueId comes from Interlocked.Increment, so ids are always positive and UniqueId & mask is a valid index. Capacity is a power of two and load stays at or below 50%. Probing therefore always ends at an empty slot. Add and Grow are consistent with each other. _noEntries is never written, because the first Add always grows it.
  • Hot reload and walks: CloneToForHotReload iterates _entries and skips null slots. The old array stays intact after a grow, so walks in progress are safe. The pooled-array reuse hazard is gone.
  • Style: tabs, braces and comments follow the repo conventions.
  • Open item, screenshot diffs: the latest Azure build (238683) still reports 118 changed on Linux and 174 on Windows, out of 2458. The previous build reported 130 and 178. A count that barely moves between two builds suggests a baseline or environment difference, not this change. The affected samples (Buttons, Grid, CalendarView, Clipboard, Gamepad) are mostly static. I can't confirm either way from here.
    • Before merge, please check whether master shows the same set of diffs.
    • If the diffs are new, look at GetAllDetails() order first, through the enter/leave and theme walks.
    • Gamepad_* and ClipboardTests have no relation to DP storage. Their presence points to baseline drift.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 238854 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • DisplayInformation.png-dark
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • DropDownButtonPage.png-dark
    • DynamicFont.png-dark
    • DynamicFont.png
    • Examples.png
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
  • skia-windows-screenshots: 2458 changed over 2486

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedIconPage.png-dark
    • AnimatedVisualsTestbedPage.png
    • ApplicationViewMode.png
    • AppWindowClosing.png
    • AppWindowPresenters.png
    • ArcSegment.png-dark
    • Attributed_text_Simple.png
    • AutoBorderStretchwithleftmargin.png-dark
    • AutoBorderStretchwithtopmargin.png-dark
    • AutoBorderStretchwithtopmargin.png
    • AutomationProperties_StructureAndProps.png-dark
    • AutomationProperties_StructureAndProps.png
    • BadgeNotificationTests.png-dark
    • BadgeNotificationTests.png
    • Basics.png-dark
    • Basics.png
    • BezierSegment.png-dark
    • BezierSegment.png
    • BitmapIcon_Generic.png-dark
    • BitmapIcon_Generic.png

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 238854 has failed on Uno.UI - CI.

@morning4coffe-dev morning4coffe-dev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verified by inspection at head 1a077d4: the open-addressed table in DependencyPropertyDetailsCollection.cs keeps capacity a power of two with load at or below 50%, so every probe loop terminates. The shared length-1 _noEntries array is never written, because the first Add grows it. Grow re-inserts from the stored UniqueId and leaves the old array intact for walks in progress. No Dispose callers remain in src/Uno.UI at head. The walkers (EnterProperties/LeaveProperties in DependencyObject.PropertySystem.mux.cs, InnerUpdateChildResourceBindings in DependencyObject.Theming.cs) handle null entries. Public surface is unchanged. WinUI parity does not apply: this is internal storage.

I did not build or run anything, so this is code review by inspection only. The allocation and timing numbers are the author's.

Findings, most important first:

  1. CI is red at head 1a077d4 (Azure build 238854). Uno.UI - CI (Tests - Android Skia Runtime Tests 3) fails with "The test results file ... does not contain any results". The retry stage's filter decodes to SamplesApp.Tests.Given_ShellLayout.When_Focus_Mode_Exit_Button_Idles_It_Hides_Until_Activity Cleanup | invalid-test-for-retry. That test does not exist in this tree, so the retry ran nothing. This looks like a stale failure list on the agent, not this change. Please rerun to confirm. PublishTestResults also reports test failures in the result files. I could not read the failing test names without Azure auth. Please post them, or confirm they also fail on master.

  2. Screenshot diffs: build 238854 reports 118 changed on Linux and 2458 of 2486 on Windows. PR #25307 (base master, no storage change) shows the same counts, so this looks like baseline drift on this branch family rather than an effect of this change. Please confirm against a master run before merge.

  3. Minor: When_Borders_Are_Created_Then_Allocation_Stays_Bounded asserts under 3200 bytes per new Border(). The PR's measured value is 3,032, a margin of about 5%. GC.GetAllocatedBytesForCurrentThread is sensitive to TFM and build configuration, so this may be flaky on some CI legs. Consider a looser ceiling.

  4. Minor: GetAllDetails() now returns the live table in hash order. The doc comment covers the snapshot semantics. I read the three call sites and none obviously depends on sibling order, but I did not trace Enter/Leave side effects. A runtime test that pins Enter/Leave order would make that explicit.

Once #25047 is confirmed green, I would expect to approve it.

@MartinZikmund

Copy link
Copy Markdown
Member Author

@ebariche @Xiaoy312 can you rebase and finalize this one please?

MartinZikmund and others added 2 commits October 27, 2026 14:22
DependencyPropertyDetailsCollection rented 16-slot buckets from a
LinearArrayPool plus a short[] offsets array indexed by the global
UniqueId. Since the DependencyObject disposal path was removed, nothing
returns the final arrays, so every element paid a fresh DPD[32] and
short[16] for two properties, and the offsets array grew with the
property's global id.

Replace it with an open-addressed table keyed by UniqueId (linear
probing, at most half full, starting at 4 slots), allocated directly.
No offsets array, no pool, and a replaced array is never cleared under
an in-flight GetAllDetails enumeration. Drop the unreachable Dispose.

new Border() 3320 -> 3032 B, Button 5896 -> 5608 B; 7 properties with
ids ~3000: 1651 -> 816 B. GetValue hit/miss unchanged within noise.

Refs #24754

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NL1zD4nmcDjrcPhceNXFNm
@ajpinedam
ajpinedam force-pushed the dev/mazi/perf-dp-details-exact-size branch from 1a077d4 to e0fe1c7 Compare October 27, 2026 18:24
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @ajpinedam's task in 18s —— View job


Re-review of #25047 (head e0fe1c7f)

Verdict: ship, pending green CI.

Issues: 0 high, 0 medium, 1 low. The low one is a note and has no inline comment.

Method: code review by inspection only. I did not build or run anything, so there is no compile or runtime validation from me.

Findings

  • Table correctness: Capacity is a power of two and load stays at or below 50%, so probing always reaches an empty slot. Add and Grow use the same hash. Grow leaves the old array intact for walks in progress. The shared _noEntries array is never written, because the first Add grows it.
  • Dispose removal: No Dispose callers remain under src/Uno.UI. The only external reader of the table is DependencyObject.Store.cs:86, which wraps GetAllDetails() in a null fallback.
  • Low, test margin: When_Borders_Are_Created_Then_Allocation_Stays_Bounded asserts under 3200 bytes per new Border() (Given_DependencyPropertyDetailsCollection.cs:79). The PR's measured value is 3,032, so the margin is about 5%. This may be flaky across TFMs or configurations. Consider a looser ceiling, or assert the slot count only.

Open items before merge

  • Rebase on master, as requested.
  • Azure build 238854 was red: an Android Skia runtime-test retry that ran nothing, plus 118 Linux and 2458 Windows screenshot diffs. Those counts look like baseline drift, since Gamepad_* and ClipboardTests have no relation to DP storage. Please rerun after the rebase and compare against a master run.

@unodevops

Copy link
Copy Markdown
Contributor

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

@ajpinedam
ajpinedam enabled auto-merge October 27, 2026 19:12
@nventive-devops

Copy link
Copy Markdown
Contributor

The build 241733 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • DisplayInformation.png-dark
    • ClipboardTests.png-dark
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • DynamicFont.png-dark
    • DynamicFont.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_Enumeration.png-dark
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
  • skia-windows-screenshots: 2458 changed over 2492

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png
    • AppBarButtonWithIconTest.png
    • ApplicationViewMode.png
    • AppWindowClosing.png-dark
    • AppWindowTitleBar Properties.png-dark
    • AppXamlDefinedResources.png
    • Attributed_text_FontSize_Changing.png-dark
    • AuthenticationBroker_Cancel.png
    • AutoBorderStretchwithtopmargin.png
    • AutomationPropertiesExtensions_Role.png-dark
    • AutoSuggestBox_Icons.png-dark
    • AutoSuggestBox_Icons.png
    • BasicEnability.png-dark
    • BasicEnability.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • BitmapIcon_Sizing.png-dark
    • BitmapIcon_Sizing.png
    • Border_CornerRadius.png-dark
    • Border_CornerRadius.png

@ajpinedam
ajpinedam merged commit faeb561 into master Oct 27, 2026
51 checks passed
@ajpinedam
ajpinedam deleted the dev/mazi/perf-dp-details-exact-size branch October 27, 2026 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.0 PRs only. For issues, use the Release field. area/automation Categorizes an issue or PR as relevant to project automation area/performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DependencyPropertyDetailsCollection wastes most of its DependencyPropertyDetails[] bucket per stored property

7 participants