Repository navigation
fix: Declare Name on DependencyObject like WinUI - #25184
MartinZikmund wants to merge 29 commits into
Conversation
|
Claude finished @MartinZikmund's task in 20s —— View job Review of PR #25184Verdict: ship, with one minor item to resolve. Issues by severity: 0 blocking, 1 minor (inline), 0 nits. I reviewed the diff by inspection only. I did not build the code or run any tests. Cross-cutting notes
|
|
Claude finished @MartinZikmund's task in 21s —— View job Answers to the open review questionsI read the code and did not change anything. I did not build or run tests.
No, keep it as a separate
The Two points to be aware of:
Inline review comment on I did not check this one. I did not run the unit test without the |
|
Claude finished @MartinZikmund's task in 34s —— View job Review of PR #25184 (latest push:
|
|
Claude finished @MartinZikmund's task in 33s —— View job Review of PR #25184 (latest push:
|
|
Claude finished @MartinZikmund's task in 26s —— View job Review of PR #25184 (latest push:
|
|
Claude finished @MartinZikmund's task in 32s —— View job Review of PR #25184 (latest push)Verdict: ship, with two minor inline items to reconcile. 0 blocking, 0 important, 2 minor (both description/code mismatches). Scope: inspection only. I did not build or run tests. The checkout is shallow, so I could not diff against Cross-cutting notes
|
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
Native WinUI's XamlReader can't resolve test-assembly types, so the XamlReader variants now skip NativeWinUI. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
WinUI only raises the always-notify for DependencyObject_Name when the effective value is written. A Style setter under a local Name now stays silent, as in WinUI. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
The null -> "" coercion allocated a ModifiedValue on every Name set, including every x:Name'd element, and still stored non-string values. Normalize null and cast up front instead: a non-string now throws InvalidCastException before storing, as in WinUI. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
VSM reads VisualState and VisualStateGroup names in loops on every GoToState. Mirror DependencyObject_Name into a field, like WinUI's m_strName and FrameworkElement's NameCache, instead of a full GetValue. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
With VisualState.Name now defaulting to "" like WinUI, GoToState("")
would match an unnamed state. WinUI returns false without changing
state (VisualStateManager_Partial.cpp GoToStateImpl skips an empty
name). Also fix the dead null fallbacks in ToString.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
Move the Uno-only #if inside the test body so discovery sees it, and give the brush Name binding a FallbackValue: as in WinUI (oracle), the path doesn't resolve, so the fallback shows rather than a silent "". Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
Registered with DependencyObject's statics, the name got a UniqueId in a
details bucket no element otherwise uses, so every named element paid a
16-slot bucket (+128 B per new Border { Name = "x" }). Register it from
FrameworkElement's initializers, where master registered its Name DP:
named Border allocation is back to master's 2,160 B.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
Clearing a coercion that was never applied allocated a ModifiedValue just to store Unset. Every set of a coerced DP whose coercion returns the base value hit it, Name included (48 B per x:Name'd element). Skip the allocation when nothing is coerced; an existing ModifiedValue still gets its coercion cleared. Name goes back to a plain null -> "" coercion instead of its own type check in the store, since Uno doesn't type-check other DPs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
TextElement.Name isn't read on a hot path, so it reads the DP directly again; only the VSM lookups keep a field. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
Name change callbacks go back to master's plain AreDifferent check, so this PR leaves DependencyObject.Store.cs unchanged. WinUI's notify on an unchanged effective write is tracked as a follow-up. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
GoToState is only about 3% slower reading the DP directly, so VisualState and VisualStateGroup read Name through GetValue again; only FrameworkElement keeps a field. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa
ff77575 to
73115a6
Compare
There was a problem hiding this comment.
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.
|
Claude finished @MartinZikmund's task in 17s —— View job Review of PR #25184 (synchronize at
|
|
Claude finished @MartinZikmund's task in 13s —— View job Scope check for PR #25184 (synchronize at
|
GitHub Issue: closes #25370, part of #21129
Note
Stacked on #25307 (base branch
dev/mazi/findname-namescope, GitHub stack #24389). The diff shows only this PR's commits.Stack, bottom to top:
NamePropertyRestack notes:
chore: Drop stale MenuFlyout Name TODObecame empty (#23935 already replaced that line) and was dropped.test: Restore DO Name storage tests for FindNamebrings back three #25307 tests that need this PR's storage. The last commit,perf: Drop the VisualState Name caches, removes the VisualState/VisualStateGroup field caches (see the GoToState section).DependencyObject.Store.csis still identical tomaster.PR Type:
🐞 Bugfix
What changed? 🚀
In WinUI,
FrameworkElement.NamePropertyisKnownPropertyIndex::DependencyObject_Name(FrameworkElement.g.cpp:1403). It is declared onDependencyObject, and the XAML parser writes everyx:Namethere. Uno declared it onFrameworkElement, sox:Nameon a brush,MenuFlyout,Run,VisualState,ColumnDefinitionand so on was never stored. ReadingFrameworkElement.NamePropertyon those objects threw (owner validation) or failed the callback cast.This PR:
DependencyObject.NameProperty(internal, ownerDependencyObject, default"").FrameworkElement.NamePropertyforwards to the same instance, so the public API is unchanged. The changed callback forwards toFrameworkElement.OnNameChangedand keeps the localNamecache. The runtime owner validation (ValidatePropertyOwner) needs no exemption. TheDependencyProperty_Ownerreflection unit test listsFrameworkElement.Nameas declared on another type, like its other re-exposed DPs.ShouldSetXName) andXamlReaderstorex:Nameon every non-FrameworkElementDO throughMarkupHelper.SetXName, even when the type declares its own CLRName. This follows WinUI'sGetRuntimeNameProperty, which always resolves x:Name to DO_Name.TextElement.Name,VisualState.NameandVisualStateGroup.Namefollow the DP, asTextElement::get_NameImplandVisualState::get_Namedo. All three read the DP throughGetValue. OnlyFrameworkElementkeeps its existingNameCache, set from the DP's backing-field callback. A field cache forVisualStateandVisualStateGroupwas evaluated and dropped (see the GoToState section below).nullname to"", matching WinUI's HSTRING storage. Like other DPs, Name is not type-checked.DependencyPropertyDetails: clearing a coercion that was never applied used to allocate aModifiedValuejust to storeUnset, on every set of any coerced DP whose callback returned the base value. It now skips the allocation, and an existingModifiedValuestill gets its coercion cleared. Without this, the Name coercion would add 48 B to every named element compared to master.DependencyObject.Store.csitself is unchanged by this PR.FrameworkElement's static initializers, where master registered its own Name DP. Its storage then shares a details bucket with the otherFrameworkElementproperties, and a named element allocates no more than on master.VisualStateManager.GoToState(control, "")returnfalsewithout activating an unnamed state, as WinUI does (VisualStateManager_Partial.cppGoToStateImplskips an empty name).FrameworkElement.Name, as in WinUI. Without that,{Binding Path=Name}on a brush would start returning the x:Name, where WinUI returns"".#25308, stacked on this PR, uses this storage for the flyout presenters' AutomationId (WinUI's
GetOwnerName).WinUI vs Uno
The WinUI column comes from a WinAppSDK 2.4.0 oracle app. The Uno columns come from Skia desktop runtime tests (
Given_DependencyObject_Name).FrameworkElement.NamePropertyreturns the same instance on every readNameDP onDependencyObjectGetValue(NameProperty)ReadLocalValue""/ Unset""/ UnsetSetValue("X"), thenGetValue,ClearValue"X", then"""X", then""RegisterPropertyChangedCallbackon a brush (A, B, clear)"""""A"three times), brush and BorderClearValueof an unset name{Binding Path=Name}: Run / brush (withFallbackValue)"R"/ fallback"R"/ fallback"R"/ fallbackNameunder a localName(callbacks)S, then localS, thenClearValue(callbacks)GoToState(control, "")with an unnamed statefalse, no statefalsefalse, no stateBorder.SetValue(NameProperty)<->Border.NameNamepropertyNameSetValue(NameProperty, "Q")on Run / VisualState / VisualStateGroup ->.Name"Q""Q"SetValue(NameProperty, null)""null(FE)""GetProperty(typeof(Border), "Name")Still different from WinUI:
FindNamewith WinUI #21129.PropertySystem.cpp:1538,:2137-2141). Uno keeps master's "raise only on change" behaviour, soDependencyObject.Store.csstays untouched here. A write masked by a higher precedence (e.g. a Style setter under a localName) is silent on both, which a test covers.Allocations
Measured with a headless Skia harness. The figures are bytes allocated per operation on the UI thread, the median of 7 rounds, and they reproduced exactly across alternating runs. Wall-clock is noise on this machine and isn't reported. The named rows ran 10k operations per round, the templated Button 2k.
efa29548ba2)32e9d5f8b19)new Border { Name = "x" }new SolidColorBrush()+ x:Name (MarkupHelper.SetXName)new VisualState()+ x:NameButton: create, enter, layout, leaveGoToState(PointerOver/Normal)on a loadedButtonThe "PR now" column was measured while VisualState and VisualStateGroup still had a Name field cache. Dropping it removes one string field (8 B) from each of those objects, so the VisualState row is now slightly lower. That wasn't re-measured.
Per 10k operations: named Border +0 (it was +1.76 MB before the fixes), and named brush or VisualState +2.7 MB. The brush and VisualState cost is the new storage itself: on master a brush dropped its x:Name and VisualState kept it in a CLR field, while both now hold it in DependencyObject_Name's property details, as WinUI does. The templated Button delta comes from its named VisualStates and VisualStateGroups.
GoToState: VisualState/VisualStateGroup Name cache, evaluated and dropped
An earlier revision mirrored
VisualState.NameandVisualStateGroup.Nameinto a field (like WinUI'sCDependencyObject::m_strName), because VSM scans these names on everyGoToState. It was dropped: realGoToStatecalls are at most about 3% slower without it (and the CheckBox case is within noise). Only the artificial full-scan miss shows a large relative gap, and that is about 100-300 cycles. The simpler code, whereNamereadsGetValue(NameProperty)and the backing-field callback only servesFrameworkElement, was worth more than that.This compares two builds of this PR that differ only in the
VisualState.Name/VisualStateGroup.Namegetter: the field cache or(string)GetValue(NameProperty). Each figure is the median of 4 alternating launches, each launch itself a median of 7 rounds. Thread cycles are stable, while wall-clock (about 2.9 cycles/ns here) is noisy on this machine. The miss rows callGoToStatewith a name that matches no state, so they isolate VSM's name scan over every group and state.GetValue: cycles / nsButton, PointerOver/Normal toggleCheckBox, UncheckedPointerOver/UncheckedNormal toggleButton, name not found (full scan)CheckBox, name not found (full scan)Allocations are identical in both arms: 1,688 / 3,086 / 72 / 72 B. This PR ships the
GetValuearm.Breaking changes
Both changes are WinUI-aligned with no API change. They are documented in
doc/articles/migrating-to-uno-7.md(XAML changes):FrameworkElementDO that declares its own CLRNameor"Name"DP no longer receives x:Name in that property. The name is stored inFrameworkElement.NamePropertyinstead, as in WinUI. Migration: set the type's own property with a plainName="...", or readGetValue(FrameworkElement.NameProperty).VisualState.NameandVisualStateGroup.Namedefault to""instead ofnull, as in WinUI. Migration: replaceName == null/Name ?? ...checks withstring.IsNullOrEmpty(Name).PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code
https://claude.ai/code/session_017TzDba3gSK3uYpvLmmBmaa