Skip to content

perf(theming): Skip the Loading theme pass Enter already did - #25406

Open
MartinZikmund wants to merge 4 commits into
masterfrom
dev/mazi/theme-loading-skip
Open

MartinZikmund wants to merge 4 commits into
masterfrom
dev/mazi/theme-loading-skip

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #25405

PR Type:

✨ Feature (performance)

What changed? 🚀

FrameworkElement.OnLoadingPartial re-ran UpdateAllThemeReferences on 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:

  • references registered without that walk: style and visual-state setters, and references set while the element was not live
  • a failed refresh
  • an element that left the tree
  • a pass that also carries the hot reload reason

As in WinUI, an ancestor Resources change 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 ListViewItemPresenter template 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:

Metric Before After
GridView realize-1000 first frame 624 ms 512 ms
GridView realize-1000 settled 727 ms 635 ms

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_ResourceDictionary and Given_Control all pass (188 tests).

PR Checklist ✅

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vi68uWCYVXxhcX9m6JEwSC

MartinZikmund and others added 4 commits October 13, 2026 21:01
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
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

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


Review of #25406

Verdict: fix-first (1 medium finding, 0 blocking otherwise)

  • Read the diff and the surrounding Enter/Leave theme code
  • Post inline findings

Summary

  • The optimization is small and well scoped. It is documented against depends.cpp:1056-1060, keeps the hot-reload and failed-refresh paths, and adds 3 runtime tests for the ancestor-override cases.
  • Severity counts: 1 medium, 0 high, 0 low.
  • The medium finding is about the flag's default. false means "Enter resolved everything", but a first Enter can end without a pass. Only the re-enter case, via Leave, is handled.
  • Not verified: I did not build or run the tests in this job. The review is by inspection only, and the PR's 188 passing runtime tests are the author's report.
  • Process note: the PR template's docs and screenshot-compare checkboxes are unchecked. That is probably fine for a perf change.

// 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;

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.

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.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 239297 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • ClipboardTests.png-dark
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • DisplayInformation.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • DynamicFont.png-dark
    • DynamicFont.png
    • ImageBrushInList.png-dark
    • ImageBrushInList.png
  • skia-windows-screenshots: 2458 changed over 2488

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png
    • AnimatedBackVisualSourceSamplePage.png
    • AnimatedVisualsTestbedPage.png
    • AppBarToggleButtonTest.png-dark
    • ApplicationViewSizing.png-dark
    • Application_DispatcherShutdownMode.png
    • AppWindowTitleBar Properties.png
    • Attributed_text_FontSize_Changing.png
    • AuthenticationBroker_Demo.png
    • AutoBorderStretchwithbottommargin.png-dark
    • AutomationPropertiesExtensions_Role.png
    • AutomationProperties_AutomationId.png-dark
    • AutoSuggestBoxChosenSuggestion.png-dark
    • AutoSuggestBoxChosenSuggestion.png
    • BackGesture.png-dark
    • BackGesture.png
    • Basics Pivot Test.png-dark
    • Basics Pivot Test.png
    • BasicThemeResources.png-dark
    • BasicThemeResources.png

@MartinZikmund MartinZikmund added the 7.1 PRs only. For issues, use the Release field. label Oct 14, 2026
MartinZikmund added a commit that referenced this pull request Nov 2, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 2, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 9, 2026
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 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.

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.

@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

MartinZikmund added a commit that referenced this pull request Nov 13, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 13, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 13, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 13, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 14, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 17, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 17, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 17, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 17, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 18, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 18, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 18, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.1 PRs only. For issues, use the Release field.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Skip the duplicate Loading-time theme reference pass

4 participants