Skip to content

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

Closed

Description

@MartinZikmund

What would you like to be added? 💡

Two paths in the theming / Fluent-resource layer build theme dictionaries at startup that the application can never observe. Together they account for roughly 922 KB of allocation before the first frame, on every launch.

1. The startup high-contrast pass materializes every HighContrast theme dictionary, then writes nothing.

CoreServices.NotifyThemeChange() calls ResourceResolver.UpdateSystemColorAndBrushResources(..., restoreDefaults: !Theming.HasHighContrastTheme()). On a machine that is not in high contrast — the overwhelming majority — restoreDefaults is true, and the call recursively walks the entire merged-dictionary graph. At each node it probes four theme dictionaries (HighContrast, HighContrastBlack, HighContrastWhite, HighContrastCustom) through TryGetThemeDictionary → TryGetValue → TryMaterializeLazy, so those dictionaries are fully built.

Then nothing is written. shouldUpdateResources is !restoreDefaults || <a recorded override exists>, and an override can only ever be recorded while high contrast is active — so on a first, non-high-contrast launch it is always false. The entire walk is a no-op that defeats the WeakResourceInitializer lazy-resource design it walks over.

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' constructor materializes both the Light and the Dark theme dictionary.

UpdateAcrylicBrushes() does ThemeDictionaries.TryGetValue("Default", …) and ThemeDictionaries.TryGetValue("Light", …) purely to assign 20 TintLuminosityOpacity doubles that our ported Fluent dictionaries omit (WinUI sets them inline in XAML). Because TryGetValue materializes lazy values, a Light-themed app builds the whole Dark dictionary before its first frame, and vice versa — one of the two can never be the active theme.

Why is this needed? 🤔

Measured on a 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%, which is inside the noise floor on the measuring machine (untouched, byte-identical phases drifted 6–8% between arms).

Renderer 🎨

  • Skia

For which platforms 📱💻🖥️

All platforms — this is shared Uno.UI / Uno.UI.FluentTheme code, reached from Application.InitializeSystemTheme on every head.

Anything else we need to know? 💬

Both are safe to address without behaviour change:

  • For (1), an override can only be recorded from inside the branch that requires high contrast to be active, so restoring defaults before any override exists cannot change a value. The walk can be skipped until the first override is recorded.
  • For (2), the values can be baked into the ported Fluent XAML the way WinUI does it. A comment in AcrylicBrush_19h1_themeresources.xaml warns that nullable doubles cannot be set from XAML, but that comment is carried over from MUX (it cites XAMLControlsResources.cpp) and describes MUX's own compiler bug — Uno's XAML generator unwraps nullable property types and sets TintLuminosityOpacity correctly.

Given_AcrylicBrush.When_TintLuminosityOpacity_Is_Set_By_ThemeResources already guards the acrylic values, and Given_HighContrastAdjustment covers the high-contrast behaviour.

Activity

  1. added
    kind/enhancement
    triage/untriaged
    on Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/enhancementtriage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions