Repository navigation
Description
What would you like to be added? 💡
VisualState.StateTriggers is a lazily-materialising getter: when the DP holds no list it creates a DependencyObjectCollection<StateTriggerBase>, subscribes to its VectorChanged, and writes it back through SetValue. The profile shows the tell-tale shape — a getter ending in a SetValue:
ArrayPool<short>.Rent
DependencyPropertyDetailsCollection.TryGetPropertyDetails
DependencyObject.SetValue
VisualState.set_StateTriggers <-- a setter, reached from...
VisualState.get_StateTriggers <-- ...its own getter
VisualStateGroup.ExecuteOnTriggers
VisualStateGroup.OnOwnerElementChanged
That is right for a caller intending to add a trigger, but all four consumers in VisualStateGroup only ever read: ExecuteOnTriggers (reached from three call sites — owner changed / loaded / unloaded), HasStateTriggers (just a Count > 0 check) and GetActiveTrigger (twice).
So every visual state of every templated control materialises a collection, a VectorChanged subscription, a DependencyPropertyDetails entry and a pooled-array rent — to represent no triggers at all, which is what almost every state has; only adaptive/custom-trigger states ever hold any.
Why is this needed? 🤔
A non-materialising accessor that reads the DP directly fixes it, with identical behaviour: when no collection exists there are no triggers, so each loop body would have executed zero times anyway and HasStateTriggers would have returned false. A caller that genuinely adds a trigger still goes through StateTriggers and gets the collection created lazily exactly as before.
Measured impact 📊
| Workload | Metric | Before | After | Δ |
|---|---|---|---|---|
list.scroll-step |
alloc / step | 133,277 B | 121,814 B | −8.6 % |
list.scroll-step |
time / step | 1.6278 ms | 1.5791 ms | −3.0 % |
control layout.full-pass |
alloc | 4,096,259 B | 4,096,127 B | ±0 |
control grid.full-pass |
alloc | 51,833 B | 51,833 B | ±0 |
control tree.build |
alloc | 21,946,936 B | 21,942,484 B | ±0 |
Same 2,000-item virtualised ListView workload, 3 runs of the full set in identical order, median. Measured on a tree that already has the resource-scope enumerator fix applied.
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