Repository navigation
Description
What would you like to be added? 💡
GetResourceDictionaries is a yield return iterator, so every call allocates a state machine. It is called once per theme reference per element entering the tree, on top of every implicit-style lookup (GetImplicitStyle) and every {StaticResource} visual-tree retrieval (ResourceResolver.TryVisualTreeRetrieval).
While a virtualised ListView materialises containers during a scroll, <GetResourceDictionaries>d__219 is the single largest allocator in the profile at 6.3 %, reached through FrameworkElement.OnFwEltLoading → UpdateResourceBindings → UpdateAllThemeReferences → UpdateThemeReference.
Why is this needed? 🤔
Returning a readonly struct enumerable with a struct enumerator removes the allocation while leaving the walk unchanged — still lazy, still yielding the containing dictionary first, then non-empty ancestor Resources nearest-first, then Application.Resources, and still short-circuiting at the caller's first match. It still implements IEnumerable<ResourceDictionary> so the two cold .ToArray() callers keep working, while foreach binds to the struct enumerator and allocates nothing.
WinUI's equivalent walk (ScopedResources::TraverseVisualTreeResources) is likewise a plain loop that allocates nothing, so this moves Uno towards WinUI rather than away.
Measured impact 📊
| Workload | Metric | Before | After | Δ |
|---|---|---|---|---|
list.scroll-step |
alloc / step | 154,522 B | 133,264 B | −13.8 % |
list.scroll-step |
alloc / realised container | 6,718.4 B | 5,794.1 B | −13.8 % |
list.scroll-step |
time / step | 1.6573 ms | 1.6444 ms | −0.8 % (noise) |
control layout.full-pass |
alloc | 4,096,383 B | 4,095,809 B | ±0 |
control grid.full-pass |
alloc | 51,833 B | 51,833 B | ±0 |
control tree.build |
alloc | 21,929,730 B | 21,976,875 B | ±0 |
control dp.set-get |
alloc | 48,001 B | 48,001 B | ±0 |
A ListView over 2,000 items with a two-TextBlock DataTemplate and 23 realised containers, scrolled 137 px per step (deliberately not a multiple of the item height, so every step straddles items and forces recycling), driven through the dispatcher tick. 3 runs of the full workload set in identical order, median.
The layout and grid workloads are unmoved because their trees are dirtied in place rather than re-entered — this cost is paid on Enter, which is what list virtualisation does constantly.
Renderer 🎨
- Skia
For which platforms 📱💻🖥️
All platforms 🌍
Anything else we need to know? 💬
Found by allocation profiling — dotnet-trace attributed by type and call stack — of a headless app that project-references the real framework, then measured before/after with the same harness. Allocation figures are deterministic (byte-identical across runs); wall-clock is reported only from a quiet machine alongside untouched control workloads that would expose drift. Full methodology, raw runs and control workloads: specs/059-performance-improvements/evidence.md.
Activity
MartinZikmund commentedon Oct 14, 2026
Details from duplicate #24522 that are not in this issue yet:
{ThemeResource}reference from Phase A ofUpdateThemeReference(N references mean N walks and N iterators; ListViewItemPresenter has 41+); twice per element Enter for the implicit-style lookup (ApplyStylesruns from bothEnterImpland the Loading pass); and everyResourceTreeRetrievalviaResourceResolver.TryVisualTreeRetrieval.GC.GetAllocatedBytesForCurrentThread, median of 7 rounds, headless Skia):