Skip to content

test: Prove DP storage ignores registration order - #26284

Open
MartinZikmund wants to merge 1 commit into
masterfrom
dev/mazi/dp-storage-order-tests
Open

MartinZikmund wants to merge 1 commit into
masterfrom
dev/mazi/dp-storage-order-tests

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: part of #21129

Related: #24754 (closed by #25047), #25047, #25214.

PR Type:

💬 Other... (Please describe): tests only. They guard the perf behavior #25047 shipped.

What changed? 🚀

#25047 replaced DependencyPropertyDetailsCollection's 16-slot buckets (indexed by DependencyProperty.UniqueId >> 4) with a small open-addressed table. A side effect worth guarding on its own: a property's storage cost no longer depends on when it was registered relative to the other properties an object sets. With buckets, the first property set in an otherwise untouched id range cost a fresh 16-slot bucket (128 B). That is what forced #25184 to delay DependencyObject.Name's registration behind a holder class, and it is what lets #25214 drop that holder.

This PR adds only tests (carved out of #25214, where they were mixed with the Name refactor) so the property can't silently regress:

  • When_Property_Is_Registered_Far_From_The_Others_Then_Storage_Costs_The_Same: an object sets one property plus a neighbor registered just before, just after, or far away from it. Slots and bytes must match.
  • Hot reload cloning carries every local value over.
  • ClearValue keeps the other properties addressable, and re-setting doesn't duplicate details.
  • The cached DataContext details stay correct with many (attached) properties in the table.
  • GetAllDetails lists each set property exactly once.

Fails before: with the pre-#25047 storage file (faeb561948f^1) swapped into current master, the registration-order test fails: Expected:<(16, 1528)>. Actual:<(32, 1960)> (slots, bytes). The two existing sizing tests fail as well (16 slots for one or two properties). The other four new tests pass on both storages; they are correctness guards for the table's probing and snapshot paths.

Measured: what #25047 bought on master

Arms, each a Release build of Uno.UI + headless Skia host, net10.0, measured with the same harness source:

Allocation: bytes allocated on the UI thread (GC.GetAllocatedBytesForCurrentThread()), per object or per dictionary, after a warm-up of the same action. 3 alternating launches per arm. Every row was identical across launches (spread ≤ 0.5 B), and a null arm (byte-identical copy of B in another directory) matched B exactly.

Workload A A′ B B − A′
new Border() 1,536 1,544 1,544 0
new Border { Name } 1,952 1,960 1,800 −160 (−8.2%)
new SolidColorBrush() 360 368 368 0
10k Borders in tree, per Border (create + attach + layout) 44,578 44,606 44,234 −372 (−0.8%)
10k named Borders in tree, per Border 44,617 44,673 44,425 −247 (−0.6%)
10k templated Fluent Buttons in tree, per Button 153,461 153,449 150,467 −2,982 (−1.9%)
300-brush ResourceDictionary in code, per dictionary 256,160 258,568 210,568 −48,000 (−18.6%)
300-brush ResourceDictionary via XamlReader, per load 1,309,961 1,312,540 1,264,540 −48,000 (−3.7%)
same, every brush also has x:Name 1,758,521 1,761,112 1,713,112 −48,000 (−2.7%)

(A named SolidColorBrush can't be measured on master: setting FrameworkElement.NameProperty on a brush throws there, which #25184 fixes.)

CPU: thread cycles per op (QueryThreadCycleTime) on the UI thread, median of 7 in-process reps after a warm-up rep, 9 alternating launches per arm (DOTNET_TieredCompilation=0). A sweep is GetValue over every public DP on the type's hierarchy plus 12 common attached ones (94 / 123 / 114 DPs), mixing set and unset. Cells are median of the 9 launches [min–max].

cycles/op A′ B B (null copy) Verdict
Border, get set property 34.9 [30.1–40.4] 33.1 [27.5–37.2] 33.7 [27.7–37.6] no change
Border, get unset property 56.3 [48.2–68.9] 52.1 [43.6–63.7] 52.2 [44.4–60.4] no change
Button (in tree), get unset property 54.0 [49.4–69.9] 52.8 [44.1–62.7] 53.4 [44.7–65.5] no change
Border sweep (94 DPs) 61.9 [57.4–84.1] 71.6 [54.1–81.9] 75.4 [54.9–94.6] no change
Button sweep (123 DPs) 60.8 [56.1–78.6] 63.9 [53.3–77.6] 65.2 [53.5–83.0] no change
TextBlock sweep (114 DPs) 59.5 [57.9–81.5] 74.9 [57.1–83.6] 61.4 [55.7–91.8] no change
Border SetValue (Tag) 306.8 [293.5–373.0] 331.0 [267.0–366.8] 296.8 [267.0–381.9] no change

The null test is the key column: two byte-identical B builds in different directories differ by up to 22% on a median (TextBlock sweep 74.9 vs 61.4) and 11% on SetValue. Every A′/B delta sits inside that floor and inside overlapping ranges, so CPU: no measurable change; allocation: a real, deterministic win, concentrated where objects set few properties in otherwise untouched id ranges (named elements, brushes in dictionaries, templated controls).

Method notes: per-thread allocation counters don't see render-thread allocations (this change doesn't touch that thread). The machine was otherwise idle apart from IDE language servers (no builds), and CPU numbers are per-thread cycles.

Validation

  • Compile: Uno.UI + Uno.UI.UnitTests (net10.0, UnoFastDevBuild), and a Release build of Uno.UI + headless runtime for the measurements.
  • Runtime (unit tests): Uno.UI.UnitTests, 4,524 tests: 4,489 passed, 23 skipped, 12 failed, all 12 the known timezone-dependent When_Gregorian_FixedDate* tests. Given_DependencyPropertyDetailsCollection: 12/12 pass on this branch, 3/12 fail on the pre-perf: Size DependencyProperty storage to the properties set #25047 storage (above).

PR Checklist ✅

🤖 Generated with Claude Code

Guard #25047's storage table: a property's storage cost must not depend
on its UniqueId relative to the others an object sets. On the previous
id-bucketed storage the order test fails (16 vs 32 slots, 1,528 vs
1,960 B). Also cover hot reload cloning, ClearValue, the cached
DataContext details among many properties, and GetAllDetails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 10, 2026 10:05
@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label Nov 10, 2026
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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


Review of #26284: DP storage registration-order tests

Verdict: ship. I found no blocking issues. I reviewed the diff only and did not build or run the tests, so the pass/fail numbers below are the PR description's, not mine.

Issues by severity: blocker 0, major 0, minor 0, nit 2 (below). I posted no inline comments.

Summary

  • The PR changes one test file and adds no runtime code, so there is no public API, DP registration or platform-suffix concern.
  • Style follows AGENTS.md: tabs, Allman braces, no skipped or ignored tests, no event Action.
  • Static initialization order in Given_DependencyPropertyDetailsCollection (padded properties, then _attachedProperties) and in OrderObject (Prev, First, Next, then the padded Away) is deterministic. FarProperty therefore really does get a distant UniqueId.
  • MeasureStorage warms up first, then takes the minimum of 3 runs. That is a reasonable way to keep a GC.GetAllocatedBytesForCurrentThread() assertion stable. The "equal-length names" comment explains why the names are fixed, which is useful.
  • The PR description shows the registration-order test failing on the pre-perf: Size DependencyProperty storage to the properties set #25047 storage (Expected:<(16, 1528)>. Actual:<(32, 1960)>). That covers fails-before/passes-after for the property this PR guards.

Nits (non-blocking)

  • The exact-byte equality assertion in When_Property_Is_Registered_Far_From_The_Others_Then_Storage_Costs_The_Same could become flaky if allocation behavior changes, such as a different JIT or tiered-compilation setting. If it flakes, compare slot counts strictly and allow a small byte tolerance.
  • Four of the five new tests pass on both the old and new storage, as the description says. They are correctness guards, not regression tests for perf: Size DependencyProperty storage to the properties set #25047, so the test names should not overstate what they prove.

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.

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 245164 found UI Test snapshots differences: skia-linux-screenshots: 249, skia-windows-screenshots: 306

Details
  • skia-linux-screenshots: 249 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • AnimatedBackVisualSourceSamplePage.png
    • AnimatedVisualsTestbedPage.png
    • AppWindowTitleBar Properties.png-dark
    • AutomationProperties_StructureAndProps.png
    • AnimatedBackVisualSourceSamplePage.png-dark
    • BitmapIcon_Foreground.png-dark
    • BitmapIcon_Foreground.png
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png
    • AppWindowTitleBar Properties.png
    • AutomationProperties_StructureAndProps.png-dark
    • BasicAcrylicBrushTest2.png-dark
    • BasicAcrylicBrushTest2.png
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
  • skia-windows-screenshots: 306 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedVisualsTestbedPage.png
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • AnimatedBackVisualSourceSamplePage.png
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • ClipboardTests.png
    • AnimatedVisualsTestbedPage.png-dark
    • BasicAcrylicBrushTest2.png-dark
    • BasicAcrylicBrushTest2.png
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png

@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.

These guard the right thing. WinUI keeps local values in a sparse vector_map<KnownPropertyIndex, EffectiveValue> on CDependencyObject, so per-object cost never depended on where a property's index falls, and this pins the same property for the open-addressed table. Two small test notes inline.

}

var dataContext = new object();
SUT.DataContext = dataContext;

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.

DataContextPropertyDetails is lazily cached, and DataContext is set here only after the 64 attached properties have already grown the table, so the cache is probably filled after the last Grow() and the test never shows it surviving a rehash. Could you set and read DataContext first, then add the attached properties to force growth, then assert AreSame?

return o;
}

private static DependencyPropertyDetailsCollection GetCollection(DependencyObject o)

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.

GetEntries below repeats this _properties reflection and also reflects into _entries. Could it be GetCollection(o).GetAllDetails()? That drops the dependency on the private _entries field.

@mergify

mergify Bot commented Nov 10, 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

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