Repository navigation
fix(skia): suspend recycle-pooled element visuals - #23447
DerekRaven wants to merge 7 commits into
Conversation
XAML Styler drift detected on
|
There was a problem hiding this comment.
Pull request overview
This PR addresses a Skia-specific performance issue where ItemsRepeater recycled (pooled) elements can remain composed and continue driving the render loop (e.g., via indeterminate ProgressRing / Lottie invalidations) even after their item is removed, leading to sustained high CPU while nothing is visible.
Changes:
- Add a Skia-only internal
UIElement.IsVisualSuspendedForRecyclePoolingflag that drivesVisual.IsVisiblewithout changing publicUIElement.Visibility. - Update
RecyclePoolto suspend visuals onPutElementCoreand eagerly restore them onTryGetElementCore. - Add a Skia runtime test plus a SamplesApp manual repro sample, and document the behavior in
Uno-UI-Performance.md.
Note: The PR description uses Fixes #23446; if the repo’s PR conventions require fully-qualified issue links, update this to Fixes https://github.com/unoplatform/uno/issues/23446.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Uno.UI/UI/Xaml/UIElement.skia.cs | Introduces a Skia-only internal suspension flag and makes ShowVisual respect it. |
| src/Uno.UI/UI/Xaml/Controls/Repeater/RecyclePool.cs | Suspends pooled element visuals on recycle and restores them on reuse (Skia only). |
| src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Repeater/Given_ItemsRepeater.cs | Adds a Skia-only runtime test validating suspension while pooled and restoration on reuse. |
| src/SamplesApp/SamplesApp.Samples/Windows_UI_Xaml_Controls/Repeater/ItemsRepeater_RecycledSpinner.xaml | Adds a manual repro UI demonstrating the “recycled spinner keeps rendering” scenario. |
| src/SamplesApp/SamplesApp.Samples/Windows_UI_Xaml_Controls/Repeater/ItemsRepeater_RecycledSpinner.xaml.cs | Implements repro logic and CPU measurement/readout for manual validation. |
| doc/articles/Uno-UI-Performance.md | Documents the pooled-visual suspension behavior and guidance for older versions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23447/wasm-skia-net9/index.html |
|
The build 217897 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-23447/wasm-skia-net9/index.html |
|
The build 218527 found UI Test snapshots differences: Details
|
A RecyclePool keeps a recycled element parented until it is reused, so on the Skia composition path the pooled element keeps rendering at its stale position. Continuously-animating content it hosts (e.g. an indeterminate ProgressRing, whose Lottie re-invalidates the canvas from its own Render) then keeps the render loop awake at full frame rate indefinitely, with nothing visible on screen (~100% of one core at idle). Suspend the element's visual when it enters the pool and restore it when the pool hands the element back, via internal composition state only — the element's public Visibility is untouched, and the restore is eager because the reuse arrange can early-out and skip ShowVisual. - Repro: SamplesApp ItemsRepeater_RecycledSpinner. Measured on Skia X11: ~1.4 cores pinned after item removal before the fix; 0.00 cores within ~1s after it (and back to animating when the element is reused). - Test: When_Item_Removed_Then_Pooled_Element_Visual_Suspended_Until_Reuse (fails without the RecyclePool change, passes with it). Repeater + MUX repeater runtime suites pass (108/108). - Docs: note the behavior in Uno-UI-Performance.md (Skia specifics). Addresses #23446. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Drop redundant DependencyObject from FindDescendant<T> generic constraint; DependencyObject is a base class on WinAppSDK so 'class, DependencyObject' triggers CS0450. The method body only needs 'where T : class', which compiles on both WinAppSDK and Uno. - Reformat the DataTemplate comment per XamlStyler to clear style drift. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Measured on the WinAppSDK head, the recycled-spinner mechanism readout is True / False / True: current WinUI clears the DataContext on recycle (ViewManager MustClearDataContext), which Uno's Repeater port predates. The ring still stays active there — WinUI just pays nothing for it. State both expectations instead of the Skia-only one. Co-Authored-By: Claude Fable 5 <[email protected]>
7adf9fe to
0910e59
Compare
The sample ships in the same PR as the RecyclePool fix, so its copy
described the pre-fix behavior ("stays at ~100% of one core") as the
actual outcome. Reword the sample description, in-app instructions, and
mechanism readout as before/after-fix diagnostics so the text stays
accurate on fixed builds. Addresses review feedback.
Co-Authored-By: Claude Fable 5 <[email protected]>
The in-app CPU meter only reflects the render loop on software-rasterized targets; on GPU-accelerated desktops both phases read near idle, so it cannot demonstrate the fix. Add a passive SKCanvasElement probe whose RenderOverride counts composed frames, sampled at 1 Hz: ~1-2 frames/s when the loop idles vs full frame rate while it is pinned, on any GPU. CompositionTarget.Rendering is unsuitable — subscribing forces the render loop awake on both Uno Skia and WinUI. Keep the CPU meter as a secondary signal with its scope stated. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23447/wasm-skia-net9/index.html |
The SKCanvasElement probe missed frames: per-visual picture caching replays unchanged visuals without invoking their paint, so the probe only counted its own invalidations and read idle while the Lottie animated. Subscribe to the Uno-internal CompositionTarget.FrameRendered instead — raised once at the end of every composed frame, and InternalsVisibleTo covers the Skia sample heads. Validated on Skia X11: ~60 frames/s while the spinner animates, 0-1 frames/s within one second of removing the item (fix active), mechanism readout True/True/True. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23447/wasm-skia-net9/index.html |
|
The build 220553 found UI Test snapshots differences: Details
|
|
|
The instructions stated the mechanism line always shows a stale DataContext (WinUI clears it on recycle), and the CPU meter pointed GPU desktops at 'the frame probe' even on targets where the probe is unavailable and the frame line already names an external alternative. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23447/wasm-skia-net9/index.html |
|
The build 220571 found UI Test snapshots differences: Details
|
|
|
|
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or it will be closed in 10 days. |
morning4coffe-dev
left a comment
There was a problem hiding this comment.
The suspension is paired at pool put/take, leaves public Visibility intact, survives an arrange while pooled, and restores eagerly when reuse does not trigger another arrange. The Skia render path skips invisible visuals, addressing the render-driven spinner loop without detaching pool entries.
Retain the explicit remaining WinUI difference: ViewManager clears DataContext when the repeater assigned it. This patch intentionally does not port that ownership cleanup, so visual suspension is not full recycle-lifecycle parity. Source approval; conflicts must still be reconciled.
|
This PR was closed because it has been stalled for 10 days with no activity. |
What
On the Skia composition path, an element recycled by
ItemsRepeater(viaRecyclePool) stays parented and composed until it is reused. If it hosts continuously-animating content — e.g. an indeterminateProgressRing, whose Lottie re-invalidates the canvas from its ownRender()— the render loop never idles again after the item is removed: ~100% of one core, full-canvas repaints, with nothing visible on screen.Fixes #23446.
How
"Elements in the pool are not composed", encapsulated in the pool itself:
RecyclePool.PutElementCoresuspends the element's visual;TryGetElementCorerestores it on reuse — covering every pool consumer and every reuse path.UIElement.IsVisualSuspendedForRecyclePooling(Skia-only) that drivesVisual.IsVisiblewithout touching the element's publicVisibility— no app-observable state changes, no interference with bindings or visual states.ShowVisual), andShowVisualrespects the flag so an arrange while pooled cannot resurrect the visual.ViewManager::ClearElementToElementFactory/MustClearDataContext) — Uno's Repeater port predates that change. That is a separate parity gap (tracked in ItemsRepeater: DataContext not cleared on recycle (missing WinUI MustClearDataContext parity) #23624), and measurably not a fix for this bug: running the repro sample on the WinAppSDK head (real WinUI) reportsstillParented=True / dataContextUnchanged=False / ringIsActive=True— the pooled ring keeps animating on WinUI even after the clear; WinUI just renders it for free.Validation
Repro:
ItemsRepeater_RecycledSpinnerSamplesApp sample — two templates so the removed spinner element is recycled but never reused; includes a mechanism readout, a passive frames-per-second probe (the primary render-loop signal — full frame rate while pinned vs ~1–2 frames/s once idle), and an in-app CPU meter (meaningful on software-rasterized targets only; GPU-accelerated desktops read near-idle CPU even while the loop is pinned).Measured on Skia X11 (external 1 Hz sampling of
/proc/<pid>/stat):Control: the same app idling on a static
ItemsRepeatersample measures 0.00 cores.Runtime test:
When_Item_Removed_Then_Pooled_Element_Visual_Suspended_Until_Reuse— realized → composed; pooled → still parented, suspended, publicVisibilityuntouched; reused → same element instance, composed again. Fails without theRecyclePoolchange, passes with it.Existing suites: Repeater + MUX repeater runtime tests pass (108/108).
Docs
Uno-UI-Performance.md(Skia specifics) documents the new behavior, plus theElementClearing/ElementPreparedworkaround guidance for earlier versions — including the trap that re-activation on reuse cannot be left to bindings (no re-fire when the new item produces identical values).🤖 Generated with Claude Code