Skip to content

Reduce the per-reference cost of applying {ThemeResource} #25396

Open

Description

@MartinZikmund

What would you like to be added? 💡

Make applying {ThemeResource} references cheaper per element. For each reference, today's mechanism:

  • registers a ResourceBinding, and ResourceBinding derives from BindingBase, so each one is a full DependencyObject with its own property store,
  • keeps those bindings in a Dictionary<DependencyProperty, Dictionary<Precedence, ResourceBinding>>,
  • allocates a new WeakReference<ResourceDictionary> for every ThemeResourceReference pinned to a dictionary,
  • allocates a GetResourceDictionaries iterator for each ancestor walk in UpdateThemeReference,
  • runs UpdateAllThemeReferences twice for every element: once at Enter (the WinUI behavior, depends.cpp:1056-1060) and again in FrameworkElement.OnLoadingPartial.

Why is this needed? 🤔

Templates with many theme references pay this cost for every container. The WinUI ListViewItemPresenter template (adopted by the default ListView/GridView styles in #25389) carries 41 {ThemeResource} attributes per item. A 1,000-tile GridView realize allocation trace attributes about 145 MB to ResourceBinding, 100 MB to the iterator, 40 MB to ThemeResourceReference and about 120 MB to the nested dictionaries. The Loading-time pass is about 20% of first-frame CPU.

For which platforms 📱💻🖥️

Skia (all heads)

Anything else we need to know? 💬

Measured with a local GridView/ListView harness on Win32 Skia, as part of the #25389 performance work.

Activity

  1. added
    7.1
    on Oct 14, 2026
  2. removed
    7.1
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/performancekind/enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions