Repository navigation
perf(theming): Cut per-reference theme resource allocations - #25403
MartinZikmund wants to merge 2 commits into
Conversation
Every {ThemeResource} on an element allocated a ResourceBinding that was
a full DependencyObject, a per-property dictionary to hold it, its own
WeakReference to the pinned dictionary and an ancestor-dictionary
iterator on each refresh. Templates with many theme references pay this
per container; the ListViewItemPresenter template carries 41.
- ResourceBinding is a plain object; the collection is a flat list
- theme references share one weak reference per ResourceDictionary
- the ancestor lookup in UpdateThemeReference no longer allocates
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vi68uWCYVXxhcX9m6JEwSC
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vi68uWCYVXxhcX9m6JEwSC
97785e1 to
c7548b5
Compare
|
Claude finished @MartinZikmund's task in 34s —— View job Review summaryVerdict: fix-first. The code in the diff looks sound. The main problem is that the PR description doesn't match what the branch contains. Issues: 1 major (below), 2 minor (inline). Cross-cutting concerns
|
| // and new items can be added when resource bindings are evaluated. | ||
| => _cachedAllBindings ??= _bindings.ToArray(); | ||
|
|
||
| public IEnumerable<ResourceBinding>? GetBindingsForProperty(DependencyProperty property) |
There was a problem hiding this comment.
GetBindingsForProperty now allocates a List<ResourceBinding> on every hit. The old version returned Dictionary.Values and didn't allocate a list. This PR is about cutting allocations, so check the callers. If any run per reference, consider a non-allocating shape: a TryGet(property, precedence) or a struct enumerator over the flat list. Or add a note on why the allocation is acceptable.
|
|
||
| var binding = new ResourceBinding(resourceKey, updateReason, context, precedence ?? DependencyPropertyValuePrecedences.Local, setterBindingPath); | ||
| SetBindingInternal(dependencyProperty, binding); | ||
| if (dependencyProperty == null) |
There was a problem hiding this comment.
Minor: this no longer goes through SetBindingInternal, so the null check and TryRegisterInheritedProperties(force: true) are duplicated here. The original order ran TryRegisterInheritedProperties before the null check; here the check runs first, which is harmless. Consider a short comment saying the registration call is kept deliberately for parity, so it isn't dropped later as dead code.
|
Claude finished @MartinZikmund's task in 25s —— View job Review summaryVerdict: fix-first (one description/code mismatch to resolve), otherwise looks good. Issues: 1 medium, 0 high, 0 low.
|
| } | ||
|
|
||
| TryRegisterInheritedProperties(force: true); | ||
|
|
There was a problem hiding this comment.
The PR description says FrameworkElement.OnLoadingPartial now skips the Loading-time theme pass when Enter already resolved everything, but the diff doesn't touch FrameworkElement.cs. OnLoadingPartial (FrameworkElement.cs:373-387) still calls UpdateThemeBindings(ResourceUpdateReason.ResolvedOnLoading) unconditionally. Either that change is missing from the branch or the description is stale. The measurements and the stated behavior change (ancestor Resources edits between Enter and Loading no longer picked up) should match what ships.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-25403/wasm-skia-net9/index.html |
|
The build 239296 found UI Test snapshots differences: Details
|
|
|
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
The implicit GridViewItem style is BasedOn DefaultGridViewItemStyle again, as in WinUI, so default GridView items render through the ListViewItemPresenter chrome and default to AllowDrop=True. The Fluent GridViewItemExpanded is removed. Merge after #25403, #25404, #25406, #25409, #25411 and #25413. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
morning4coffe-dev
left a comment
There was a problem hiding this comment.
TryGetValueFromResourceDictionaries walks the same dictionaries in the same order as GetResourceDictionaries(includeAppResources: false), with the same shouldCheckSystem: false lookup, so behavior is unchanged. Sharing one WeakReference per ResourceDictionary mirrors WinUI, where CThemeResource holds an xref::weakref_ptr<CResourceDictionary> (components/theming/inc/ThemeResource.h) whose control block is shared per object, and nothing calls SetTarget on it. The flat ResourceBindingCollection keeps the replace-per-(property, precedence) semantics, and the unit tests cover it. LGTM.
|
Tick the box to add this pull request to the merge queue (same as
|
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GitHub Issue: closes #25396
PR Type:
✨ Feature (performance)
What changed? 🚀
Each
{ThemeResource}reference now allocates much less per element. Motivating case: the WinUIListViewItemPresentertemplate that #25389 adopts for ListView/GridView. It carries 41 theme references per container, and it made GridView slower than the old template.ResourceBindingis a plain object, no longer aBindingBase/DependencyObject.ResourceBindingCollectionis a flat list scanned linearly, likeThemeResourceMap, instead of a dictionary per property.WeakReferenceperResourceDictionary(ResourceDictionary.WeakSelf) instead of allocating one each.UpdateThemeReferenceno longer allocates an iterator. It still walks once per reference, as WinUI does.The duplicate Loading-time theme pass, also listed in #25396, is now its own PR.
Numbers. Win32 Skia, Release, local ListView/GridView harness with a non-virtualized 1,000-tile GridView.
Stacked on #25389, single round, before → after this change alone:
Allocation trace for the whole GridView-1000 run:
ResourceBinding−172 MB, ancestor iterator −186 MB, the per-property binding dictionaries (~166 MB) gone, per-referenceWeakReference−42 MB.On master alone, 3 rounds plus a null copy, measured together with the Loading-pass PR:
Timings on master alone were within noise.
Validation.
Given_ThemeResource,Given_ElementTheme,Given_Theme_Materialization,Given_ResourceDictionary,Given_FrameworkElement_ThemeResources,Given_Controlall pass (185 tests).~Theme|~Resourceall pass (453), including the newGiven_ResourceBindingCollection.PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code
https://claude.ai/code/session_01Vi68uWCYVXxhcX9m6JEwSC