Repository navigation
perf(uno-ui): Reuse boxes on the inherited-property and hit-test paths - #24525
Conversation
|
Claude finished @MartinZikmund's task in 2m 10s —— View job Review complete ✅Todo list
Verdict: Ship — no blocking issues foundThis is a tightly-scoped, mechanical refactor and it holds up under inspection:
No SOLID/layering, async/cancellation, DependencyProperty registration, or cross-platform-suffix concerns apply here — this PR doesn't touch any of those surfaces. No new warnings or No inline comments were posted since no concrete defects were found. |
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved moderate findings remain in test cleanup, the ButtonBase coercion path, and per-instance storage overhead.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
This PR reduces boxing allocations in inherited-property and managed hit-test paths while adding regression coverage.
Changes:
- Reuses boxed boolean and hit-testability values.
- Uses concrete inherited-property callback storage and fixes box caches.
- Adds inherited hit-test visibility coverage.
File summaries
| File | Summary |
|---|---|
src/Uno.UI/UI/Xaml/UIElement.Pointers.Managed.cs |
Reuses hit-testability boxes. |
src/Uno.UI/UI/Xaml/DependencyObject.Store.cs |
Avoids disposable boxing and documents value comparison. |
src/Uno.UI/UI/Xaml/DependencyObject.AncestorsDictionary.cs |
Reuses boxed booleans. |
src/Uno.UI/UI/Xaml/Controls/Control/Control.cs |
Reuses the boxed false value. |
src/Uno.UI/Helpers/Boxes.cs |
Corrects cached box field types. |
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Media/Given_VisualTreeHelper.cs |
Adds inherited hit-test visibility coverage. |
Review details
Suppressed comments (2)
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Media/Given_VisualTreeHelper.cs:113
- The platform skip is expressed by conditionally adding a hard
[Ignore]via#if. Runtime tests usePlatformConditionfor platform-specific coverage; mark this asPlatformCondition(ConditionMode.Include, RuntimeTestPlatforms.Skia)instead of compiling an ignored test on every native target. That keeps the test discoverable and states precisely where the managed-pointer implementation under test exists.
[TestMethod]
[RunsOnUIThread]
#if !UNO_HAS_MANAGED_POINTERS
[Ignore("Hit-test visibility coercion is only used by managed hit testing.")]
#endif
src/Uno.UI/UI/Xaml/DependencyObject.Store.cs:1448
- Because
_inheritedPropertiesis anInheritedPropertiesDisposable?field on everyDependencyObject(the field is atDependencyObject.Store.cs:77), this change inlinesInheritedPropertyChangedCallbackDisposable's two references into every object. The old outer struct held one callback reference plus_owner; the new one holds the callback's two references plus_owner, so nullable storage grows even for objects that never register inherited properties. Please use a reference-backed wrapper or provide a net-memory measurement before taking this per-instance footprint tradeoff.
// Typed concretely: the only caller passes this struct, and an IDisposable field would box it.
private readonly InheritedPropertyChangedCallbackDisposable _inheritedPropertiesCallback;
private readonly DependencyObject _owner;
public InheritedPropertiesDisposable(DependencyObject owner, InheritedPropertyChangedCallbackDisposable inheritedPropertiesCallback)
- Files reviewed: 6/6 changed files
- Comments generated: 3
- Review effort level: Lite
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24525/wasm-skia-net9/index.html |
|
The build 233999 found UI Test snapshots differences: Details
|
038941e to
f0461ce
Compare
|
Claude finished @MartinZikmund's task in 1m 21s —— View job Review complete ✅Todo list
Verdict: Ship — 0 blocking, 0 moderate, 0 minor findingsThis is a re-review of the current HEAD against
Re-verified the core boxing changes independently on this pass ( No inline comments were posted since no concrete defects remain. |
There was a problem hiding this comment.
🔵 Needs a closer look
It touches core dependency-property inheritance and managed hit-testing coercion paths where subtle regressions can be hard to detect despite good test coverage.
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 0 new
- Review effort level: Lite
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24525/wasm-skia-net9/index.html |
|
The build 234484 found UI Test snapshots differences: Details
|
|
|
f0461ce to
5fd8e12
Compare
|
Claude finished @MartinZikmund's task in 2m 34s —— View job Review complete ✅Todo list
Verdict: Ship — 0 blocking, 0 moderate, 2 minor findingsThis is a re-review of the current HEAD ( Verified independently:
Two minor (non-blocking) findings posted inline:
No SOLID/layering, async/cancellation, DependencyProperty-registration, or platform-suffix concerns apply to this diff. No new warnings or |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24525/wasm-skia-net9/index.html |
|
The build 236282 found UI Test snapshots differences: Details
|
|
Claude finished @MartinZikmund's task in 1m 30s —— View job Review complete ✅Todo list
Verdict: Ship — 0 blocking, 0 moderate, 0 minor findingsThis is a re-review of current HEAD (
Re-verified the rest of the diff is otherwise unchanged from the prior (Sept 29) review pass — No SOLID/layering, async/cancellation, DependencyProperty-registration, or platform-suffix concerns apply to this diff. No inline comments were posted since no concrete defects remain. |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24525/wasm-skia-net9/index.html |
|
The build 236916 found UI Test snapshots differences: Details
|
|
|
Two values were boxed on paths that run per element, once per element of a whole subtree: - InheritedPropertiesDisposable held its callback as IDisposable, boxing the readonly InheritedPropertyChangedCallbackDisposable struct on every registration, though the concrete type is statically known. - CoerceHitTestVisibility returns object, so each of its five returns boxed a HitTestability. HitTestVisibilityProperty inherits, so one coercion re-coerces the subtree below it, boxing once per element. AreDifferent records the invariant this relies on: boxed DP values are compared by value, so a ReferenceEquals fast path there would change change-detection for shared boxes. The AncestorsDictionary, Control.CoerceIsEnabled and Boxes-table parts of the original change landed on master with the cached-boxes sweep. When_Ancestor_Not_HitTestVisible_Then_Descendant_Collapsed covers the inheritance leg of hit-test visibility, which the existing geometry-focused hit-test tests did not. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012QzKQawubFcPPX9JSoZLkX Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014vRr9HufCgBEVgt1z8J5Ay
Typing the callback field concretely removed the box but grew the struct from two references to three, adding 8 B to every DependencyObject. The callback's child store is always the owner, so store only the parent's weak reference and unregister directly, dropping the nested callback struct. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_019C454B8usXZRfvcjWT1BB4
Also link the test to #24524. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_019C454B8usXZRfvcjWT1BB4
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01G7PsEU6gSpLZXrYuK8WWpt
97ce555 to
181b264
Compare
|
Claude finished @MartinZikmund's task in 1m 38s —— View job Review complete ✅Todo list
Verdict: Ship — 0 blocking, 0 moderate, 0 minor findingsConfirmed the current HEAD (
All prior reviewer findings (Copilot's three, morning4coffe-dev's one, and the two minor notes from the Sept 29 automated pass) are resolved in this state — no regressions reintroduced. No SOLID/layering, async/cancellation, DependencyProperty-registration, or platform-suffix concerns apply to this diff. No new warnings or Cross-cutting note (not a code finding): the CI screenshot-diff bot has reported a very large, consistent fraction of snapshots changing ( No inline comments were posted since no concrete defects were found. |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24525/wasm-skia-net9/index.html |
|
The build 236964 found UI Test snapshots differences: Details
|
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
GitHub Issue: closes #24524
PR Type:
🔄 Refactoring (no functional changes, no api changes)
What changed? 🚀
Note
Rebased onto master on 2026-09-29. The
AncestorsDictionary,Control/ButtonBase.CoerceIsEnabledandBoxesenum-table parts below have since landed on master through the cached-boxes sweep (d7a77ad and theUno.UI.Helpers.Boxesnamespace refactor), so this PR now carries only theInheritedPropertiesDisposablefield typing, the sharedHitTestabilityboxes, theAreDifferentremark and the new test. The measurements below were taken against the pre-sweep base and overstate what remains.Four values were boxed on paths that run per element, and in two cases once per element of an entire subtree:
AncestorsDictionarystores probe results in an object-valuedHashtableEx, so everySetboxed aboolduring inherited-property re-registration — nowBoxes.Box(bool), the helper that already exists for this.InheritedPropertiesDisposableheld its callback asIDisposable, boxing a readonly struct on every registration. It now stores the callback's state inline — just the parent store's weak reference, since the callback's child store is always the owner — so it stays two references wide (a concretely typed callback field would have grown everyDependencyObjectby 8 B).CoerceHitTestVisibilityreturnsobject, so each of its five returns boxed aHitTestability. That property inherits, so one coercion re-coerces the subtree below it — once per element.Control.CoerceIsEnabled(andButtonBase.CoerceIsEnabledfor a command whoseCanExecuteis false) did the same with a barefalseonIsEnabledProperty, which also inherits and, viaOnIsEnabledChanged→UpdateHitTest(), runs immediately before the hit-test coercion over the same subtree.Two supporting changes:
Boxes' enum tables were broken.VerticalAlignmentBoxes,StretchBoxesandNullableDoubleBoxesdeclared value-typed fields, soBox(VerticalAlignment)/Box(Stretch)boxed on every call and cached nothing. They areobject-typed now. This has no measurable effect today (both overloads are uncalled and the one live use runs once per property registration) — it is included because this PR's whole thesis is "share the box", and leaving a…Boxeshelper that doesn't box is a trap for the next caller.AreDifferentnow records the invariant everything here depends on: boxed DP values are compared by value, never by reference, so aReferenceEqualsfast path added there later would silently change change-detection for shared boxes.Measured impact 📊
GC.GetAllocatedBytesForCurrentThread, median of 7 rounds, two runs per side, against master. A box is 24 B on x64, so the absolute deltas double as box counts:ListView(2,000 items) scroll stepListViewItemCheckBoxButtonThe win is a flat ~24 B per element coerced, so it scales with subtree size, not with a workload's total — the 40-control page shows a smaller percentage than one
ListViewItemwhile saving 16× more bytes.Per-instance footprint, measured because
InheritedPropertiesDisposablelives inline on everyDependencyObject. Re-measured after rebasing onto current master (01f8a9f), same harness; "concrete field" is the first revision of this PR, which typed the disposable's field as the callback struct:new Border()new Grid()new Button()The first revision's −16 B was the removed hit-test box (−24 B) partly offset by the struct growing from two references to three (+8 B per
DependencyObject). Storing only the parent's weak reference keeps the struct at master's size, so construction now saves the full box.The same re-measurement for the per-step workloads (medians, two runs per side, bytes within ~250 B between runs):
ListViewscroll step 160,641 B → 154,695 B (−5,946 B, −3.7 %); Enter + LeaveButton17,264 B → 17,080 B (−184 B). The earlier tables were taken on an older master, so their absolute values differ, but the deltas match.Scope and limits. Skia-measured only — the hit-test path also compiles for WASM (
UNO_HAS_MANAGED_POINTERS), where the effect is expected but not demonstrated. Wall-clock is not reported: it varied by more than the effect between identical runs. Gen0 over 1,000 scroll steps moved 15 → 14, within the ±1 this instrument shows across builds, so this is an allocation claim, not a frame-time one.Estimate accuracy, since these came from an automated audit: the inherited-property items were estimated at ~3.9 KB/step and measured ~1.4 KB (~2.8× optimistic); the hit-test item was estimated ~4.4 KB and measured ~4.2 KB. The first pair alone was too small to ship, which is why they are bundled.
Validation ✅
Runtime tests, Skia Desktop —
Given_UIElement,Given_VisualTreeHelper,Given_InputManager,Given_InputInjector,Given_ThemeResource,Given_ElementTheme,Given_Style,Given_VisualStateManager,Given_NonFE_DataContextBinding,Given_ResourceDictionary_DataContext,Given_BindingExpression,Given_DependencyObjectExtensions,Given_DependencyProperty_AttachedPropagation,Given_ListViewBase,Given_Button,Given_CheckBox: 969 run, 957 passed, 22 skipped, 1 inconclusive, 11 failed.The failures are the
Given_ListViewBaselayout-rounding/timeout set and theGiven_UIElementclip/transform set, all of which reproduce identically on a build of the merge-base (verified by building master in a separate worktree and running the same classes: 563 passed / 5 failed, same five names).Given_VisualTreeHelper.When_Ancestor_Not_HitTestVisible_Then_Descendant_Collapsedwas added: the existing hit-test tests all exercise geometry, and none asserted that a descendant follows its ancestor'sIsHitTestVisible/Visibility— which is exactly the inheritance mechanism whose boxed values changed here.It was mutation-checked: with the coercion changed so a descendant no longer inherits an ancestor's
Collapsed, it is the only failure inGiven_VisualTreeHelper(1 of 10; the nine geometry-based hit-test tests still pass). So it guards the inheritance leg specifically, rather than duplicating existing coverage. It also passes on the merge-base, i.e. it asserts behaviour this PR preserves.After rebasing onto
01f8a9fand the review fixes: runtime tests, Skia Desktop —Given_VisualTreeHelper,Given_Button,Given_Control,Given_NonFE_DataContextBinding,Given_DependencyObjectExtensions,Given_ElementTheme,Given_ThemeResource: 188 run, 188 passed.Uno.UI.UnitTests: 4,129 passed, 12 failed — allWhen_Gregorian_FixedDate*, a known pre-existing local failure (they assume a UTC machine; green on CI).Perf axis: work removed 📊
The
≈ boxescolumn above is the deterministic operation count for this change — every eliminated box is one heap allocation that no longer happens, and the count follows directly from the 24 B box size on x64:ListViewscroll stepThis is an allocation change, so the tables above are the performance evidence: the CPU benefit is the GC pressure removed, not fewer instructions in the coercion walk itself.
CPU time is deliberately not reported, and that is demonstrable rather than asserted. Re-measuring on this machine with a thread-cycle counter (
QueryThreadCycleTimesampled on the UI thread, where the work runs) showed that reversing the order of the two measurement phases flips the sign of the apparent result, and that the spread within a single phase reaches 74–97 % on the same build and workload. A timing column produced here would report machine state, not the change. Wall-clock is worse and is not reported either — as already noted above, it varied by more than the effect between identical runs. The byte figures are unaffected: allocation is deterministic and reproduces to ~10 B on the low-variance workloads.Provenance. Measured with a headless Skia app (
Uno.UI.Runtime.Skia.Headless) project-referencing the framework, with Fluent resources merged; bytes viaGC.GetAllocatedBytesForCurrentThreadon the dispatcher thread, median of 7 rounds, two runs per side. Not BenchmarkDotNet — this repository has no BenchmarkDotNet harness, and the workload runs on the dispatcher thread, which is where the allocation counter has to be read.PR Checklist ✅
Screenshots Compare Test Runresults. — to check once CI has runFollow-ups this PR deliberately leaves open
PropagateInheritedNonLocalPropertiesstill allocates aHashtableExper call (the audit's item 3 for that finding); theCount == 0early return is the current mitigation._childrenStoresis a copy-on-writeImmutableList, so register/unregister each allocate a fresh array.Boxoverloads inUno.UI.Helpers.Boxesare currently uncalled — worth either adopting or deleting.🤖 Generated with Claude Code
https://claude.ai/code/session_012QzKQawubFcPPX9JSoZLkX
Internal tracking: unoplatform/uno-private#2349 (finding 8) and unoplatform/uno-private#2368 (finding 2), under unoplatform/uno-private#2346.