Skip to content

perf(theming): Cut ~922 KB of boot allocation from theme dictionary materialization - #24539

Merged
MartinZikmund merged 6 commits into
masterfrom
dev/mazi/perf-theme-boot
Sep 26, 2026
Merged

MartinZikmund merged 6 commits into
masterfrom
dev/mazi/perf-theme-boot

Conversation

@MartinZikmund

@MartinZikmund MartinZikmund commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

GitHub Issue: closes #24538

PR Type:

💬 Other... Performance — allocation reduction on the startup path. No API change, no behaviour change.

What changed? 🚀

Two startup paths built theme dictionaries the application can never observe. Together they cost about 922 KB of allocation before the first frame, on every launch, on every platform.

1. ResourceResolver.UpdateSystemColorAndBrushResources — skip the high-contrast restore walk until there is something to restore.

CoreServices.NotifyThemeChange() calls it with restoreDefaults: !Theming.HasHighContrastTheme(), which is true on any machine not in high contrast. It then walked the whole merged-dictionary graph, probing four theme dictionaries per node (HighContrast, HighContrastBlack, HighContrastWhite, HighContrastCustom). Those probes go through TryGetThemeDictionary → TryGetValue → TryMaterializeLazy, so the HighContrast dictionaries of the entire Fluent graph were materialized — and then nothing was written, because shouldUpdateResources is !restoreDefaults || <an override was recorded> and no override can exist yet.

An override is only ever recorded from inside that same branch, which requires high contrast to be active. So restoring defaults before any override has been recorded cannot change a value — it is a no-op computed the expensive way. The walk now returns early while no override is recorded, tracked by a _highContrastResourceStateCount counter: incremented in the GetValue factory, decremented when a restore removes a state (ConditionalWeakTable exposes no count). So the skip also comes back after high contrast is turned off and every override has been restored. Entries lost to GC only keep the count above zero, which costs a no-op walk and never skips a real restore. The full walk still runs whenever high contrast is active, and whenever an override exists to restore.

This path is new in 7.0 — UpdateSystemColorAndBrushResources does not exist in 6.7.103, where the call site is a // TODO Uno comment. It arrived with 1afcec4b94 feat(skia): implement high contrast support.

2. XamlControlsResources — bake TintLuminosityOpacity into the Fluent XAML instead of patching it from the constructor.

UpdateAcrylicBrushes() did ThemeDictionaries.TryGetValue("Default", …) and …("Light", …) purely to assign 20 doubles our ported dictionaries omitted. Since TryGetValue materializes lazy values, a Light-themed app built the entire Dark dictionary before its first frame, and vice versa — one of the two can never be the active theme. The 20 values now sit inline on the AcrylicBrush resources the way WinUI sets them, and the constructor code path is gone.

This restores WinUI parity — it does not invent an Uno mechanism. MUX sets these values inline in
XAML
, not from code-behind: controls/dev/Materials/Acrylic/AcrylicBrush_themeresources.xaml carries
TintLuminosityOpacity on all 20 brushes, and the values in this PR were diffed against it — an exact
match, Dark and Light. The only acrylic code in MUX's XamlControlsResources.cpp is a lookup, whose
own comment explains it: "a workaround to force the Nullable type to be registered as a known
type, which somehow doesn't otherwise get registered for some apps which need it." That is a WinRT
type-registration quirk, not a value assignment, and it looks up a single brush in the Default
dictionary only — it never materializes both themes.

Uno's UpdateAcrylicBrushes was therefore compensating, in code, for attributes dropped when the Fluent
dictionaries were ported — as its own comment said: "Our ported Fluent dictionaries omit the
TintLuminosityOpacity that WinUI sets inline on these AcrylicBrush resources." This PR fills that gap the
way WinUI does. The "low level compiler bug ... nullable doubles" warning lives in
AcrylicBrush_19h1_themeresources.xaml, the legacy system-XAML dictionary; that text appears nowhere in
the MUX sources, and Uno's XAML generator unwraps nullable property types correctly (verified end to end
below). MUX's type-registration workaround is deliberately not ported: Uno has no equivalent WinRT type
activation, and porting it would re-materialize the Default dictionary at constructor time.

Measurements

Headless Skia boot harness, medians of interleaved A/B process launches. Allocation is deterministic on this path: byte-identical medians and minimums across sweeps, and stable to 0.02% between a quiet machine and one at 94% CPU.

phase before after delta
process start → OnLaunched 994,376 B 472,680 B −52.5%
new XamlControlsResources() 1,277,072 B 215,024 B −83.2%
window + activate 113,568 B 801,528 B +605.8%
total to first idle 2,920,344 B 1,998,336 B −31.6%

The rise in the window/activate phase is the active theme's materialization moving from constructor time to first use — the same work, later. The net ~922 KB is genuinely eliminated: the inactive theme dictionary and the four HighContrast dictionaries are never built at all.

This is an allocation result, not a startup-time claim. Total wall-clock to first idle moved about −1%, inside the noise floor: on the measuring machine the untouched, byte-identical phases drifted 6–8% between arms, so the timing numbers are not trustworthy at that resolution.

Validation

  • Runtime tests (Skia Desktop, Given_AcrylicBrush + Given_HighContrastAdjustment + Given_Theme_Materialization): 43/43 passed, 1 skipped (a NativeWasm-only test, correctly excluded on this target).
    • When_TintLuminosityOpacity_Is_Set_By_ThemeResources passes, asserting Light = 0.85 and Dark = 0.96 and non-null through normal {ThemeResource} resolution. This is a pre-existing test, not added here.
    • All 11 high-contrast tests pass, including the activate/deactivate transitions and the HighContrastWhite/Black/Custom variant selection.
  • Unit tests (Uno.UI.UnitTests): 4166 total, 12 failed — all 12 are When_Gregorian_FixedDate*, the known pre-existing failures on a non-UTC machine, unrelated to this change. Given_ResourceDictionary's high-contrast tests (which call UpdateSystemColorAndBrushResources directly, including with restoreDefaults: true) pass, including two added here: When_HighContrast_Restore_Without_Override_Theme_Dictionaries_Stay_Lazy (the skip before any override) and When_HighContrast_Overrides_Restored_Theme_Dictionaries_Stay_Lazy (the skip after all overrides were restored; fails without the counter).
  • The 20 TintLuminosityOpacity values were diffed against the deleted C# constants: exact match, 20/20.
  • src/Uno.UI.FluentTheme/themeresources.xaml is a generated build artifact and is gitignored, so no merged file needed regenerating.

PR Checklist ✅

  • 🧪 Added Runtime tests, UI tests, or a manual test sample (for bug fixes / features, if applicable) — unit tests added for the high-contrast restore skip (see Validation); the acrylic change is guarded by the existing tests listed there, all of which were run and pass.
  • 📚 Docs have been added/updated following the documentation template (for bug fixes / features) — not applicable, no API or behaviour change.
  • 🖼️ Validated PR Screenshots Compare Test Run results. — to be checked once CI publishes them.
  • ❗ Contains NO breaking changes
  • 👀 Reviewed 2 other open pull requests (optional but appreciated!)

🤖 Generated with Claude Code

https://claude.ai/code/session_012QzKQawubFcPPX9JSoZLkX

Copilot AI lite review requested due to automatic review settings September 17, 2026 08:09
@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 3m 32s —— View job


Review complete ✅

  • Gather context (PR description, diff, changed files)
  • Review ResourceResolver.cs changes (high-contrast walk skip)
  • Review XamlControlsResources.cs changes (removed constructor patching)
  • Review AcrylicBrush_themeresources.xaml changes (inline TintLuminosityOpacity)
  • Check test coverage / validation claims
  • Post inline findings
  • Summarize review

Verdict: fix-first (one finding, not blocking-severity, but worth addressing before merge)

Findings by severity: 1 medium (test coverage / hygiene) — posted inline on src/Uno.UI/UI/Xaml/ResourceResolver.cs:69.

What I verified as correct

  • High-contrast skip logic (ResourceResolver.cs): the early return only fires when restoreDefaults=true and no override has ever been recorded, which is exactly the no-op case the PR identifies — I traced the sole caller (CoreServices.NotifyThemeChange → restoreDefaults: !HasHighContrastTheme()) and confirmed no other call site could observe a behavior change, only a timing change (lazy vs. eager walk).
  • TintLuminosityOpacity values: independently diffed all 20 removed C# constants against the new inline XAML attributes across both Default (dark) and Light theme dictionaries — exact 1:1 match, including which theme gets which value.
  • AcrylicBrush.TintLuminosityOpacity is a double? DependencyProperty; Uno's XAML generator does unwrap nullable property types for XAML-set values, so the inline attributes are functionally equivalent to the removed constructor-time assignment.
  • No dangling references to the removed private methods (UpdateAcrylicBrushes, UpdateTintLuminosityOpacity) elsewhere in the tree.

Cross-cutting concern (not tied to one line)

The perf win itself is real and well-reasoned, but it's currently unverifiable by CI: the sticky _hasHighContrastResourceStates flag (see inline comment) can only be flipped false → true, has no reset hook, and the existing Given_ResourceDictionary HC tests will flip it as a side effect the first time they run in a given test-host process — silently disabling the new fast path for every test that follows in that process, with no test asserting the skip happens in the first place. This doesn't affect production correctness (the design intentionally treats "HC was ever used" as sticky for the process lifetime), but it does mean a future regression reintroducing the eager walk would go undetected by the test suite.

Note on validation: this was a code-review by inspection (diff read, static-flow tracing, cross-referencing call sites and value tables) — I did not build or run the test suite myself in this session; the PR's own reported test results (43/43 runtime tests, 4164 unit tests with only the known pre-existing Given_ResourceDictionary unrelated failures) were taken as reported, not independently re-executed.
· branch dev/mazi/perf-theme-boot

Comment thread src/Uno.UI/UI/Xaml/ResourceResolver.cs Resolved

Copilot AI left a comment

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.

🔵 Needs a closer look

Clear the high-contrast state latch when no states remain and add coverage for the unmaterialized-resource early-return path.

Pull request overview

This PR reduces startup allocations by avoiding unnecessary high-contrast resource materialization and moving acrylic opacity values into Fluent XAML.

Changes:

  • Defers high-contrast restoration until resource overrides exist.
  • Removes eager acrylic brush patching.
  • Defines TintLuminosityOpacity values directly in theme resources.
File summaries
File Summary
src/Uno.UI/UI/Xaml/ResourceResolver.cs Adds a high-contrast materialization guard; the latch should be cleared when the final resource state is removed, with regression coverage for the early-return path.
src/Uno.UI.FluentTheme/XamlControlsResources.cs Removes constructor-time acrylic resource materialization.
src/Uno.UI.FluentTheme/Resources/Priority02/AcrylicBrush_themeresources.xaml Defines acrylic luminosity values inline for theme dictionaries.
Review details

Suppressed comments (2)

src/Uno.UI/UI/Xaml/ResourceResolver.cs:69

  • This latch is never reset when the restore path removes the last HighContrastResourceState at line 1406. After one high-contrast on→off transition, every later non-high-contrast notification still walks the entire graph and probes all four theme dictionaries; newly loaded dictionaries can therefore be materialized even though there is no state to restore. Track live state entries (or otherwise clear the guard when the final state is removed) instead of permanently recording that a state existed.
		private static bool _hasHighContrastResourceStates;

src/Uno.UI/UI/Xaml/ResourceResolver.cs:1290

  • The allocation-saving branch itself has no regression test. The existing unit coverage calls restoreDefaults: true only after an active high-contrast pass, so the latch is already set and this early return is not exercised; add coverage with an unmaterialized HighContrast* WeakResourceInitializer and assert its factory is not called by the first non-high-contrast restore.
			if (restoreDefaults && !_hasHighContrastResourceStates)
			{
				return;
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 234217 found UI Test snapshots differences: skia-linux-screenshots: 57, skia-windows-screenshots: 2310, wasm: 11

Details
  • skia-linux-screenshots: 57 changed over 2348

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • Buttons.png-dark
    • Buttons.png
    • DisplayInformation.png-dark
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • ContextRequested.png-dark
    • ContextRequested.png
    • Examples.png-dark
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • ImageIconPage.png-dark
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
  • skia-windows-screenshots: 2310 changed over 2408

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png
    • ApplicationViewMode.png
    • AppWindowClosing.png
    • AppWindowPositionAndSize.png-dark
    • AppXamlDefinedResources.png
    • Attributed_text_Simple.png-dark
    • AutoBorderStretchwithbottommargin.png-dark
    • AutoBorderStretchwithleftmargin.png
    • AutoBorderStretchwithtopmargin.png
    • AutomationPropertiesExtensions_Role.png-dark
    • AutoSuggestBoxChosenSuggestion.png-dark
    • AutoSuggestBoxChosenSuggestion.png
    • AutoSuggestBox_Reason.png
    • AutoSuggestBox_SoftKeboard.png-dark
    • Basics_Automated.png-dark
    • Basics_Automated.png
    • BeginTime_MultipleAnimations.png-dark
    • BeginTime_MultipleAnimations.png
    • BitmapIcon_Sizing.png-dark
    • BitmapIcon_Sizing.png
  • wasm: 11 changed over 1076

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • SamplesApp.Wasm.Windows_UI_Xaml_Controls.ListView.ListView_IsSelected
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Minimal
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.WinUIExpanderPage
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewSelectedItems
    • UITests.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_NavigationProperties
    • SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_EnableDevTools
    • UITests.Windows_UI_Xaml_Controls.CalendarView.CalendarView_Theming
    • UITests.Uno_Web.Http.CookieManagerTests
    • UITests.Windows_UI_Xaml_Media_Animation.ColorAnimation_Background
    • Uno.UI.Samples.Content.UITests.WebView.WebView_AnchorNavigation

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 234217 has failed on Uno.UI - CI.

MartinZikmund and others added 4 commits September 18, 2026 09:20
UpdateSystemColorAndBrushResources is called from NotifyThemeChange with
restoreDefaults: !HasHighContrastTheme(), so on a machine that is not in high
contrast it walked the whole merged-dictionary graph, probing four HighContrast
theme dictionaries per node. Those probes go through TryMaterializeLazy, so the
dictionaries were built - and then nothing was written, because
shouldUpdateResources requires either high contrast to be active or a
previously recorded override, and an override can only ever be recorded from
inside that same branch.

Restoring defaults before any override exists therefore cannot change a value.
Return early until the first override is recorded, which also keeps the
HighContrast dictionaries lazy. ConditionalWeakTable exposes no count, so the
flag is set in the GetValue factory.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012QzKQawubFcPPX9JSoZLkX
XamlControlsResources' constructor read ThemeDictionaries["Default"] and
["Light"] to assign 20 TintLuminosityOpacity doubles that our ported Fluent
dictionaries omit. TryGetValue materializes lazy values, so a Light-themed app
built the entire Dark theme dictionary before its first frame, and vice versa,
although only one of the two can ever be the active theme.

Set the values inline on the AcrylicBrush resources the way WinUI does. The
ported MUX comment claiming nullable doubles cannot be set from XAML describes
MUX's own compiler bug (it cites XAMLControlsResources.cpp); Uno's XAML
generator unwraps nullable property types.
Given_AcrylicBrush.When_TintLuminosityOpacity_Is_Set_By_ThemeResources covers
the resolved values.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012QzKQawubFcPPX9JSoZLkX
Lets unit tests drop recorded high-contrast overrides so the one-way
_hasHighContrastResourceStates latch does not leak between tests.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019C454B8usXZRfvcjWT1BB4
Asserts that restoring defaults before any override leaves the
HighContrast theme dictionary unmaterialized, and that the walk runs
again once an override has been recorded. Resets high-contrast state
after each test.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019C454B8usXZRfvcjWT1BB4
Copilot AI review requested due to automatic review settings September 18, 2026 07:30
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/perf-theme-boot branch from c364497 to 823b3e3 Compare September 18, 2026 07:30
@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label Sep 18, 2026
@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 4m 9s —— View job


Review complete ✅

  • Gather context (diff since last review, previous review findings)
  • Review ResourceResolver.cs changes (high-contrast walk skip, sticky flag)
  • Review XamlControlsResources.cs changes (removed constructor patching)
  • Review AcrylicBrush_themeresources.xaml changes (inline TintLuminosityOpacity)
  • Review Given_ResourceDictionary.cs new tests (+56 lines)
  • Check whether prior review findings (sticky flag reset, missing test coverage) were addressed
  • Post inline findings (none survived — see below)
  • Summarize review

Verdict: ship — no blocking findings

This push (refactor(theming): Add high-contrast state reset hook + test(theming): Cover skipped high-contrast restore) resolves the two gaps flagged on the prior revision, and I found no new issues to report inline.

What changed since the last review, and how it holds up:

  • Test-coverage gap (my own prior finding, ResourceResolver.cs:69): fixed correctly. ResetHighContrastResourceStates() is added as a plain internal static method with no #if guard — the right call, since IS_UNIT_TESTS is never defined inside Uno.UI itself (per .claude/rules/code-style.md), so my own suggestion to gate it behind that symbol would not have compiled. Given_ResourceDictionary.Cleanup() now calls it in [TestCleanup], and the new test When_HighContrast_Restore_Without_Override_Theme_Dictionaries_Stay_Lazy asserts materializations == 0 for the skip path and materializations == 1 once a real override exists elsewhere — solid, direct regression coverage for the exact optimization this PR introduces.
  • Sticky-latch design concern (Copilot's prior finding): not auto-reset in production, but this is intentional, not an oversight — the new test's second half deliberately proves the flag is a global, process-lifetime latch (an unrelated root dictionary takes the full walk once any override was ever recorded anywhere). Auto-decrementing would need a live count that ConditionalWeakTable can't cheaply provide. Since the flag only ever trends toward "always correct, sometimes slower" (never toward a wrong value), and the PR's target scenario is boot allocation — before any theme notification could have set an override — this is a reasonable, tested tradeoff rather than a defect.
  • Independently re-verified the TintLuminosityOpacity value tables in both theme blocks of AcrylicBrush_themeresources.xaml against the deleted C# constants (Dark values in Default, Light values in Light) — exact match, 20/20.
  • Confirmed no dangling references to the removed UpdateAcrylicBrushes/UpdateTintLuminosityOpacity/Microsoft.UI.Xaml.Media using, and that UpdateSystemColorAndBrushResourcesCore has no call path that bypasses the new guard (it's private, reached only through the two guarded public entry points).

Cross-cutting note (non-blocking)

The Azure Pipelines run linked in the comments (build 234217, predates this push) reported ~2310/2408 changed Windows screenshots and a pipeline failure. That volume is plausible as an expected consequence of this fix — AcrylicBackgroundFillColorDefaultBrush and friends back the default Fluent chrome background used across most pages, and the PR description notes the pre-fix luminosity alpha was "far too low" (rendering near-opaque) — so correcting it plausibly shifts most acrylic-backed screenshots at once. This is already tracked as an open checklist item ("Validated PR Screenshots Compare Test Run results — to be checked once CI publishes them"); flagging only so the reported pipeline failure (not just the screenshot diff count) gets confirmed as baseline-approval rather than a real build break before merge, since that run predates the latest two commits.
· branch dev/mazi/perf-theme-boot

Copilot AI left a comment

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.

🟡 Changes recommended

Clear _hasHighContrastResourceStates after restoration to preserve the allocation optimization.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread src/Uno.UI/UI/Xaml/ResourceResolver.cs Resolved
@unodevops

Copy link
Copy Markdown
Contributor

MartinZikmund and others added 2 commits September 18, 2026 11:47
The high-contrast restore walk stayed on for the rest of the process
after the first activation, because the state flag never reset.
Count live override states instead and decrement when a restore
removes one, so the walk is skipped again once nothing is left.
Entries lost to GC only keep the count high, which just costs a
no-op walk.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019C454B8usXZRfvcjWT1BB4
Asserts that once every recorded high-contrast override has been
restored, a later restore-defaults walk leaves HighContrast theme
dictionaries unmaterialized.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019C454B8usXZRfvcjWT1BB4
Copilot AI review requested due to automatic review settings September 18, 2026 09:56
@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 1m 9s —— View job


Review complete ✅

  • Gather context (diff since last review, prior review findings)
  • Review ResourceResolver.cs changes (high-contrast walk skip, sticky flag, reset hook)
  • Review XamlControlsResources.cs changes (unchanged since last review — already verified)
  • Review AcrylicBrush_themeresources.xaml changes (unchanged since last review — already verified)
  • Review Given_ResourceDictionary.cs new tests
  • Check whether prior review findings were addressed
  • Post inline findings (none — see below)
  • Summarize review

Verdict: ship — no blocking findings

This push (fix(theming): Re-enable restore skip once cleared + test(theming): Cover restore skip after HC is off) is the only delta since the last review round, and it resolves the sticky-flag concern both Copilot passes raised.

What changed and how it holds up:

  • The bool _hasHighContrastResourceStates latch is replaced with an int _highContrastResourceStateCount, incremented inside the GetValue factory (once per theme dictionary, guarded by state ??= so it can't double-count within one walk) and decremented only when _highContrastResourceStates.Remove(themeDictionary) actually removes an entry — so a restore can't decrement twice for the same dictionary.
  • The skip condition (restoreDefaults && count == 0) now correctly re-enables the fast path once every recorded override has been restored, rather than staying permanently disabled after the first HC activation — exactly the gap flagged in the prior two Copilot reviews.
  • The comment on the field honestly documents the one remaining imprecision (GC-collected ConditionalWeakTable entries never decrement the count), and correctly characterizes it as a harmless cost (an occasional no-op walk), not a correctness bug.
  • New test When_HighContrast_Overrides_Restored_Theme_Dictionaries_Stay_Lazy is a direct regression test for this exact fix: it applies an override, restores it (count 1 → 0), then asserts an unrelated, lazy HighContrast dictionary elsewhere stays unmaterialized on the next restore-defaults walk. This is the missing coverage both Copilot rounds asked for.
  • ResetHighContrastResourceStates() correctly resets both the ConditionalWeakTable and the new counter, keeping [TestCleanup] state isolation intact.

No cross-cutting concerns beyond what's already tracked in the PR checklist (screenshot-compare results pending CI).
· branch dev/mazi/perf-theme-boot

Copilot AI left a comment

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.

🟢 Approval recommended

No unresolved blocking issues were identified.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 234511 found UI Test snapshots differences: skia-linux-screenshots: 57, skia-windows-screenshots: 2310, wasm: 11

Details
  • skia-linux-screenshots: 57 changed over 2348

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • Buttons.png-dark
    • Buttons.png
    • ContextRequested.png-dark
    • ContextRequested.png
    • DisplayInformation.png-dark
    • Examples.png-dark
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • Focus_FocusVisual_Properties.png-dark
    • ImageIconPage.png-dark
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
  • skia-windows-screenshots: 2310 changed over 2408

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AndroidWindowInsets.png
    • AnimatedIconPage.png-dark
    • AppBarButtonWithIconTest.png-dark
    • AppBarToggleButtonTest.png-dark
    • ApplicationViewMode.png
    • ApplicationViewSpanningRectsPage.png
    • AppWindowFeatures.png-dark
    • AppWindowPresenters.png
    • AppWindowTitleBar Properties.png
    • Arrange_Performance01.png
    • Attributed_text_FontSize_Changing.png
    • Attributed_text_Supserscript.png-dark
    • AutoBorderStretchwithrightmargin.png
    • AutoBorderStretchwithleftmargin.png-dark
    • AutoSizedTopLeft.png
    • AutomationPropertiesExtensions_Role.png-dark
    • AutoSuggestBox_Icons.png-dark
    • AutoSizedPathCentered.png
    • AutoSuggestBox_Icons.png
    • AutoSizedTopLeft.png-dark
  • wasm: 11 changed over 1076

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_EnableDevTools
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewSelectedItems
    • UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.WinUIExpanderPage
    • SamplesApp.Wasm.Windows_UI_Xaml_Controls.ListView.ListView_IsSelected
    • UITests.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_NavigationProperties
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Minimal
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • UITests.Windows_UI_Xaml_Media_Animation.ColorAnimation_Background
    • UITests.Uno_Web.Http.CookieManagerTests
    • UITests.Windows_UI_Xaml_Controls.CalendarView.CalendarView_Theming
    • Uno.UI.Samples.Content.UITests.WebView.WebView_AnchorNavigation

@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.

LGTM! Keeping HighContrast theme dictionaries lazy when no high-contrast override is active saves ~922 KB of boot allocations across all platforms. Great performance improvement with unit tests.

@mergify

mergify Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(theming): Startup builds theme dictionaries the app never uses (~922 KB before first frame)

5 participants