Repository navigation
perf(vsm): Stop materialising empty state-trigger collections - #24235
Conversation
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
Pull request overview
This PR addresses a performance issue in Uno’s VisualStateManager trigger evaluation by avoiding the lazy materialization of an empty StateTriggers collection when call sites only need to read triggers.
Changes:
- Added a non-materializing accessor (
StateTriggersOrDefault) onVisualStateto read the DP value without creating an empty collection. - Updated
VisualStateGrouptrigger-reading paths (ExecuteOnTriggers,HasStateTriggers,GetActiveTrigger) to use the new accessor to avoid unnecessary allocations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Uno.UI/UI/Xaml/VisualStateGroup.cs | Switched trigger iteration/read logic to use StateTriggersOrDefault to avoid materializing empty collections. |
| src/Uno.UI/UI/Xaml/VisualState.cs | Introduced StateTriggersOrDefault to read StateTriggersProperty without forcing lazy collection creation. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24235/wasm-skia-net9/index.html |
|
The build 230533 found UI Test snapshots differences: Details
|
398a80a to
9a060b8
Compare
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24235/wasm-skia-net9/index.html |
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
|
The build 231013 found UI Test snapshots differences: Details
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24235/wasm-skia-net9/index.html |
|
The build 231673 found UI Test snapshots differences: Details
|
morning4coffe-dev
left a comment
There was a problem hiding this comment.
Code review assessment: reading the nullable existing trigger collection is aligned with WinUI's standard VSM path, which returns when m_pStateTriggerCollection is null rather than creating an empty collection: https://github.com/microsoft/microsoft-ui-xaml/blob/439bda90582f7892ca595a193f55dbfc6ae2010c/dxaml/xcp/components/vsm/StandardVisualStateManagerDataSource.cpp#L388-L400 . The normal StateTriggers getter still creates/subscribes the collection when needed. No blocking behavior issue found. The nullable return annotation can be clarified without replacing it with a materialized DP value.
9a060b8 to
8397ceb
Compare
|
Claude finished @MartinZikmund's task in 1m 43s —— View job Review complete
Verdict: fix-first. The approach is sound (non-materialising read accessor, read sites switched via pattern matching, no public API/behavior change), but the refactor missed one read site, which undercuts the stated completeness of the fix. Findings posted inline: 2
Other checks: no new |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24235/wasm-skia-net9/index.html |
|
The build 237145 found UI Test snapshots differences: Details
|
VisualState.StateTriggers is a lazily-materialising getter: with no list on the DP it creates a DependencyObjectCollection, subscribes to its VectorChanged and writes it back through SetValue. That is right for a caller intending to add a trigger, but all four consumers in VisualStateGroup only read -- ExecuteOnTriggers (three call sites), HasStateTriggers, and GetActiveTrigger twice. So every visual state of every templated control materialised a collection, a subscription, a DependencyPropertyDetails entry and a pooled-array rent to represent no triggers at all, which is what almost every state has. Add StateTriggersOrDefault, which reads the DP without materialising, and use it at the four read sites. Behaviour is identical: with no collection there are no triggers, so each loop body ran zero times anyway and HasStateTriggers returned false. A caller that actually adds a trigger still goes through StateTriggers and creates it lazily as before. Measured (specs/059-performance-improvements): a virtualised ListView scroll step drops from 133,277 B to 121,814 B (-8.6%) and from 1.6278 ms to 1.5791 ms (-3.0%), with the layout, grid and tree-build control workloads flat. Cumulatively with the two preceding fixes, a scroll step is down 21% on allocations. 221 visual-state and control runtime tests: every one passes except the ListViewBase set already established as pre-existing. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015DSdL5YzLhjx8CeGXZf1Au
Review feedback addressed 2026-10-09. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NHPnucPE4WuxBEhL1RJG2T
8397ceb to
21b01af
Compare
|
Claude finished @MartinZikmund's task in 14s —— View job Review summaryVerdict: ship. I re-reviewed the PR at
Counts: 0 blocking, 0 new findings. Cross-cutting notes
|
|
The build 238554 found UI Test snapshots differences: Details
|
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |

GitHub Issue: closes #24226
PR Type:
🔄 Refactoring (no functional changes, no api changes)
What changed? 🚀
VisualState.StateTriggersis a lazily-materialising getter: with no list on the DP it creates aDependencyObjectCollection, subscribes to itsVectorChangedand writes it back throughSetValue. That is right for a caller intending to add a trigger, but all four consumers inVisualStateGrouponly read —ExecuteOnTriggers(three call sites),HasStateTriggers, andGetActiveTriggertwice. So every visual state of every templated control materialised a collection, a subscription, aDependencyPropertyDetailsentry and a pooled-array rent to represent no triggers at all, which is what almost every state has.Add
StateTriggersOrDefault, which reads the DP without materialising, and use it at the four read sites. Behaviour is identical: with no collection there are no triggers, so each loop body ran zero times anyway andHasStateTriggersreturned false. A caller that actually adds a trigger still goes throughStateTriggersand creates it lazily as before.Measured impact 📊
list.scroll-steplist.scroll-steplayout.full-passgrid.full-passtree.buildSame 2,000-item virtualised
ListViewworkload, 3 runs of the full set in identical order, median. Measured on a tree that already has the resource-scope enumerator fix applied.Validation ✅
Runtime tests, Skia Desktop —
Given_VisualStateManager,Given_EventTrigger,Given_Button,Given_CheckBox,Given_RadioButton,Given_ToggleSwitch,Given_HyperlinkButton,Given_AppBarButton,Given_Style,Given_ListViewBase: 221 run, 214 passed, 11 skipped, 7 failed. Every visual-state and control test passes; the only failures are theGiven_ListViewBaseset already established as pre-existing against baseline builds in the other PRs of this series.PR Checklist ✅
Screenshots Compare Test Runresults. — to check once CI has run