Repository navigation
perf(theming): Skip the Loading theme pass Enter already did - #25406
MartinZikmund wants to merge 4 commits into
Conversation
FrameworkElement.OnLoadingPartial re-ran UpdateAllThemeReferences on every element right after Enter had done it (WinUI only does it at Enter, depends.cpp:1056-1060). For an element with dozens of theme references, such as a ListViewItemPresenter, this was ~20% of a GridView's first-frame CPU. The Loading pass now skips a live element whose references were all resolved against its live ancestors. References registered without that walk (style and visual state setters, references set while not live, a failed refresh, any element that left the tree) keep the pass. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vi68uWCYVXxhcX9m6JEwSC
Nearer-ancestor overrides of style setter and template part references, across a theme change, and a styled element moved under an overriding ancestor. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vi68uWCYVXxhcX9m6JEwSC
The skip only applies to a plain Loading pass; a pass that also carries the hot reload reason re-resolves every reference as before. 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
|
Claude finished @MartinZikmund's task in 29s —— View job Review of #25406Verdict: fix-first (1 medium finding, 0 blocking otherwise)
Summary
|
| // since the last UpdateAllThemeReferences pass that did. WinUI only refreshes theme references at Enter | ||
| // (depends.cpp:1056-1060); Uno repeats the pass at Loading, which only matters for the references added since. | ||
| // TODO Uno: drop the Loading pass once the setter flows resolve through the live ancestor walk. | ||
| private bool _hasThemeReferencesPendingLiveUpdate; |
There was a problem hiding this comment.
The flag defaults to false, which means "Enter already resolved everything". That only holds if Enter's theme block actually ran a pass. In DependencyObject.mux.cs (~L269-281), the parentTheme != _theme branch calls NotifyThemeChanged. That call can return early (theme == _theme && !forceRefresh after the RequestedTheme override, or IsProcessingThemeWalk) without calling UpdateAllThemeReferences on this element.
The Leave change you added covers a re-enter. A first Enter that takes that early return is not covered: the flag is still false, so the Loading pass is skipped although no pass ever ran. Also, NotifyThemeChanged may refresh with a cache or a different owner, and the owner == ActualInstance check then decides whether the flag gets cleared.
Suggestion: make the state positive. Set a "resolved live" flag only when a live pass actually completes, and skip Loading only when it is set. Alternatively, set the pending flag at the start of the Enter theme block and let the pass clear it. Either way, add a test where the element enters under a parent whose resolved theme equals the element's current _theme while an ancestor Resources entry is the only source of the value.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-25406/wasm-skia-net9/index.html |
|
The build 239297 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.
I checked this against WinUI's Enter theme block (core/core/elements/depends.cpp, around EnterImpl). WinUI runs UpdateAllThemeReferences only on Enter, so skipping the Loading pass for references Enter already resolved matches it, and so does no longer picking up ancestor Resources changes made between Enter and Loading. I went through every place a reference can be added (resolver and setter paths, SetThemeResourceBinding before the element is live, the failure restore), and they all mark the pending flag, so I don't see a reference that could be skipped. The LeaveImpl mark covers re-enter. 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 #25405
PR Type:
✨ Feature (performance)
What changed? 🚀
FrameworkElement.OnLoadingPartialre-ranUpdateAllThemeReferenceson every element right after Enter had already done it. WinUI only does this at Enter (depends.cpp:1056-1060). The Loading pass is now skipped for a live element whose references were all resolved against its live ancestors.The pass still runs in these cases:
As in WinUI, an ancestor
Resourceschange between Enter and Loading is no longer picked up by this pass. Setter references and Phase 2 resource bindings still are.Motivating case: #25389. Its
ListViewItemPresentertemplate has 41 theme references per container, and this duplicate pass was about 20% of a GridView's first-frame CPU.Numbers. Win32 Skia, Release, local harness with a 1,000-tile GridView. Stacked on #25389 and #25403, single round, before → after this change alone:
On master alone (3 rounds plus a null copy, together with #25403), GridView realize-100 settled went from 52.9 to 41.4 ms. Other timings stayed within noise.
Validation. Runtime tests on Skia desktop:
Given_FrameworkElement_ThemeResources(3 new tests: nearer-ancestor override of a style setter and a template part across a theme change, a styled element moved under an overriding ancestor, an element with its own theme moved),Given_ThemeResource,Given_ElementTheme,Given_Theme_Materialization,Given_ResourceDictionaryandGiven_Controlall pass (188 tests).PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code
https://claude.ai/code/session_01Vi68uWCYVXxhcX9m6JEwSC