Repository navigation
Description
What would you like to be added? π‘
The element Enter, Leave and resource-binding walks visit the collections a property holds through IEnumerable:
DependencyObject.EnterProperties/LeavePropertiesβforeachover a value typedIEnumerableDependencyObject.InnerUpdateChildResourceBindingsβforeachover a value typedIEnumerable<DependencyObject>- the
IAdditionalChildrenProviderbranch of all three (Storyboard.Children) TextBlock.UpdateThemeBindingsβforeachoverInlineCollection
DependencyObjectCollection<T>.GetEnumerator() returns IEnumerator<T>, so each of those loops boxes a List<T>.Enumerator (40 B on x64). VisualStateManager.VisualStateGroups is stored by XAML codegen as a VisualStateGroup[], which boxes an array enumerator on the same walks.
A templated control's VisualStateGroups, States, Setters, StateTriggers and Transitions each pay this on every Enter, every Leave and every theme update β so in a virtualized list, on every recycled container. An allocation profile of a scrolling ListView shows Enumerator[StateTriggerBase], Enumerator[VisualState], Enumerator[SetterBase], Enumerator[VisualTransition] and Enumerator[Inline] among the top allocated types, all rooted at these walks.
Why is this needed? π€
Indexing the backing list instead removes the allocation while visiting the same items in the same order, which is also how WinUI's CDOCollection::EnterImpl / LeaveImpl walk m_items. Values that are neither a framework DO collection nor an array keep their existing enumeration.
Measured impact π
Managed bytes allocated per iteration on the UI thread (GC.GetAllocatedBytesForCurrentThread, median of 7 rounds, two runs per side; figures reproduce within ~1%):
| Workload | Before | After | Ξ |
|---|---|---|---|
Enter + Leave Button |
18,592 B | 17,376 B | β6.5 % |
Enter + Leave CheckBox |
24,744 B | 21,848 B | β11.7 % |
Enter + Leave ToggleSwitch |
48,215 B | 44,576 B | β7.5 % |
Enter + Leave ListViewItem |
37,768 B | 32,872 B | β13.0 % |
Enter + Leave TextBox |
30,416 B | 27,024 B | β11.2 % |
| Enter + Leave a 40-control page | 796,817 B | 721,057 B | β9.5 % |
| Theme toggle on that page | 539,832 B | 514,872 B | β4.6 % |
ListView (2,000 items) scroll step |
177,950 B | 161,173 B | β9.4 % |
The saving is an exact multiple of 40 B in every case, i.e. exactly the enumerator boxes.
Renderer π¨
- Skia
For which platforms π±π»π₯οΈ
All platforms π
Anything else we need to know? π¬
Measured with a headless Skia app (Uno.UI.Runtime.Skia.Headless) that project-references the framework, with Fluent resources merged. Wall-clock is deliberately not reported: it varied by 2Γ between identical runs on the measuring machine, far above the effect. Gen0 collection counts were also captured, but at 0β2 per round they are too coarse to show a difference.
This overlaps with the empty-state-trigger work: on the scroll workload, that change alone gives β6.4 %, this one alone β9.4 %, and the two together β9.4 %. They attack the same enumerators from opposite ends, so the wins are not additive.
Activity
Jen-Uno commentedon Sep 30, 2026
QA: closing out without a manual pass. The fix in #24519 ships with automated tests (
Given_DependencyObjectCollection.cs) that exercise the change.If you still see this behaviour on a build that includes that PR, please reopen or comment here.