Repository navigation
perf(composition): Cache the rounded-clip paths (backport #24230) - #24698
mergify[bot] wants to merge 4 commits into
Conversation
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 (cherry picked from commit 2f505dc) # Conflicts: # src/Uno.UI.Composition/Composition/RectangleClip.skia.cs
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 (cherry picked from commit 9726017) # Conflicts: # src/Uno.UI.Composition/Composition/BorderVisual.skia.cs
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]> (cherry picked from commit c9e1c91) # Conflicts: # src/Uno.UI.Composition/Composition/RectangleClip.skia.cs
Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 7bed8f0) # Conflicts: # src/Uno.UI.RuntimeTests/Tests/Windows_UI_Composition/Given_CompositionGeometricClip.cs
|
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 |
|
Closing: this backport doesn't apply to this branch. Mergify committed unresolved conflict markers, which is why CI failed. #24230 fixes per-frame allocations that come from master's Profiling the #23984 scroll scenario on 6.8 puts clip-path work under 3% of UI-thread time. The remaining 6.5 → 6.8 gap comes from per-visual damage path booleans and Win32 UIA events on every layout move. Both are being fixed in separate PRs. |
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 runThis is an automatic backport of pull request #24230 done by [Mergify](https://mergify.com).