Repository navigation
perf(composition): Cache the rounded-clip paths - #24230
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 reduces GC pressure in the Skia composition renderer by caching native SKPath instances used for rounded-rectangle clipping, avoiding per-frame SKPathBuilder.Detach() allocations in hot render paths.
Changes:
- Cache
RectangleClip’s clip path and invalidate the cache on property changes. - Cache
BorderVisual’s pre-painting rounded-rect path keyed by theSKRoundRectinstance that produced it.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Uno.UI.Composition/Composition/RectangleClip.skia.cs | Adds a cached SKPath for rectangle clip paths, invalidated on property changes. |
| src/Uno.UI.Composition/Composition/BorderVisual.skia.cs | Adds a cached pre-painting rounded-rect SKPath keyed on the SKRoundRect instance to avoid per-frame rebuilds. |
💡 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-24230/wasm-skia-net9/index.html |
|
The build 230528 found UI Test snapshots differences: Details
|
74e9231 to
b548634
Compare
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24230/wasm-skia-net9/index.html |
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
|
The build 231008 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-24230/wasm-skia-net9/index.html |
|
The build 231678 found UI Test snapshots differences: Details
|
morning4coffe-dev
left a comment
There was a problem hiding this comment.
I checked the cache keys and callers: RectangleClip geometry depends on its own properties, CreateBorderPath assigns a new outer SKRoundRect, and callers copy/use the returned paths rather than mutate the borrowed cache. The remaining native-resource ownership feedback is worthwhile: RectangleClip invalidation drops the cached SKPath without disposing it, and BorderVisual has no final cached-path cleanup. Please close that deterministic lifetime path, especially for animated clip properties, before treating the performance work as complete. These Skia resource details are implementation-specific; I found no reason to claim a direct WinUI SKPath equivalent.
RectangleClip.GetClipPath built a brand new geometry on every call. Visual.Render asks for the post-painting clip several times per visual per frame, so every rounded Border produced fresh managed wrappers and native paths on every frame. InsetClip already caches its geometry. The path depends only on the clip's own properties -- GetBoundsCore ignores the visual and GetBounds applies the clip's own TransformMatrix -- so build it once, hand each caller its own reference, and release it from OnPropertyChangedCore. Every mutation reaches that hook: the setters go through SetProperty, the CreateRectangleClip overloads use object initializers, and RectangleClip does not override SetAnimatableProperty, so animations never touch these fields. The hot path is now a single null check. Measured on a 1561-element rounded tree (specs/059-performance-improvements): paint allocations drop from 519 KB to 382 KB per frame (-26%) and Gen0 collections over a 40-frame window from 1 to 0. Wall-clock is unchanged -- this is a GC-pressure win, not a throughput one. Rendering and clipping runtime tests: identical pass/fail sets before and after, 0 new failures. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015DSdL5YzLhjx8CeGXZf1Au
GetPrePaintingClipping rebuilt its round-rect geometry on every frame for every rounded border, allocating a fresh builder and geometry (and their native path) per border per frame. Cache the geometry keyed on the RoundRectangle it was built from. It is a record struct, so value equality is an exact key: changed geometry always misses. The superseded geometry is released, and every caller gets its own reference, so IntersectOwned releasing it never frees the cached instance. Measured on the same 1561-element rounded tree (specs/059-performance-improvements): paint allocations drop from 272 KB to 9.75 KB per frame (-96%), and -98% cumulatively with the two preceding fixes -- 332 B down to 6 B per element per frame. The 262 KB saved is 336 B per border, an SKPathBuilder plus an SKPath plus their handle registrations. Frame time is unchanged, confirming the same rasterization work still happens. Rendering runtime tests: identical pass/fail sets. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015DSdL5YzLhjx8CeGXZf1Au
b548634 to
9726017
Compare
|
Claude finished @MartinZikmund's task in 6m 36s —— View job Review complete
Verdict: no blocking issuesNote on prior review comments: the Copilot and
Findings (2, both low-severity / non-blocking)
Cross-cutting notes (not inline findings)
Validation performed: code review by inspection only (traced ref-counting call chains, checked |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24230/wasm-skia-net9/index.html |
|
The build 235521 found UI Test snapshots differences: Details
|
|
@mergify backport release/stable/6.7 |
✅ Backports have been createdDetails
Cherry-pick of 2f505dc has failed: Cherry-pick of 9726017 has failed: Cherry-pick of c9e1c91 has failed: Cherry-pick of 7bed8f0 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
|
@mergify backport servicing/6.8 |
✅ Backports have been createdDetails
Cherry-pick of 2f505dc has failed: Cherry-pick of 9726017 has failed: Cherry-pick of c9e1c91 has failed: Cherry-pick of 7bed8f0 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
Key the RectangleClip path cache on its round rect, as InsetClip and BorderVisual do, so it can't go stale whatever path mutates it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Claude finished @MartinZikmund's task in 2m 59s —— View job Review complete
Verdict: no blocking issuesThis sync added two commits (
Cross-cutting note (non-blocking)
Validation performed: code review by inspection — read the full current content of both |
|
@morning4coffe-dev Thanks — both lifetime gaps are closed in c9e1c91. |
🤖 Addressed PR comments up to this point
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24230/wasm-skia-net9/index.html |
|
The build 235596 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 #24221
PR Type:
🔄 Refactoring (no functional changes, no api changes)
What changed? 🚀
Two places handed out a brand-new native
SKPathon every frame for every rounded visual, becauseSKPathBuilder.Detach()transfers ownership into a new path:RectangleClip.GetClipPath—Visual.Renderasks for the post-painting clip several times per visual per frame. The path depends only on the clip's own properties (GetBoundsCoreignores thevisual,GetBoundsapplies the clip's ownTransformMatrix), so it is now built once and dropped byOnPropertyChangedCore, making the hot path a single null check. Every mutation reaches that hook: the setters go throughSetProperty, theCreateRectangleClipoverloads use object initialisers, andRectangleClipdoes not overrideSetAnimatableProperty, so animations never touch these fields.BorderVisual.GetPrePaintingClipping— allocated both anSKPathBuilderand anSKPathper rounded border per frame. Now cached and keyed on theSKRoundRectinstance it was built from;CreateBorderPathassigns a brand-new instance whenever the geometry changes, so reference identity is an exact key. The superseded path is disposed, keeping the deterministic native cleanup the oldusingprovided, and the path never escapes the call.RectangleClipwas the odd one out among the clips —InsetClipalready caches its path andCompositionGeometricClipreuses a static spare.Measured impact 📊
render.full-paintrender.full-paintrender.full-paintrender.full-paint780 rounded
Borders + 625 roundedRectangles (1,561 elements), painted throughRenderTargetBitmapwith no layout invalidation, so this is paint cost only. 5 runs each,median; allocation figures vary by <11 B across runs.
These numbers are for this PR alone, measured by building this branch and the base and running
the same workload on each — not carried over from the combined sequence. (Two related fixes measured
in sequence during development reached −98 % on the same workload, but that figure includes the
separate
ShapeVisualLINQ change, which is its own PR.)Honest scope note: frame time is unchanged — the paint walk is bound by native rasterisation,
which also confirms the same rendering work still happens. This is a GC-pressure win: at 60 fps it
is ~24 MB/s of managed garbage a rounded-border UI no longer produces, plus roughly 1,560 fewer
finaliser-tracked native Skia objects per frame.
Validation ✅
Runtime tests, Skia Desktop,
Given_Border+Given_ContainerVisual+Given_ShapeVisual+Given_Visual_Damage+Given_UIElement+Windows_UI_Xaml_Shapes.*: 671 run, 654 passed, 1 skipped, 16 failed — before and after, compared as sets of failing test names against a baseline build: 0 new failures, 0 newly fixed. The 16 include the clip tests that would catch exactly this kind of bug (When_Both_Layouting_Clip_And_Clip_DP,When_TranslateTransform_And_Clip), and they fail identically on the baseline.PR Checklist ✅
Screenshots Compare Test Runresults. — to check once CI has run