Repository navigation
Description
What would you like to be added? π‘
Two places in the composition layer hand out a brand-new native SKPath on every frame, for every rounded visual:
RectangleClip.GetClipPathresets a sharedSKPathBuilderand returnsbuilder.Detach()β andDetach()transfers ownership into a newSKPath.Visual.Renderasks for the post-painting clip several times per visual per frame.BorderVisual.GetPrePaintingClippingcallsBuildRoundRectPath, which allocates both a newSKPathBuilderand a newSKPath, per rounded border per frame.
In the paint profile of a rounded-Border tree, SkiaSharp.SKPath is the single largest type at 14.8 % of sampled allocations, with SKPathBuilder a further 5.6 %.
RectangleClip is the odd one out among the clips: InsetClip.GetClipPath already caches its path keyed on bounds, and CompositionGeometricClip reuses a static spare.
Why is this needed? π€
Both can cache, with exact keys:
RectangleClip's path depends only on the clip's own properties βGetBoundsCoreignores thevisualargument andGetBoundsapplies the clip's ownTransformMatrixβ so anOnPropertyChangedCoreoverride drops it when any property changes, 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's path can be keyed on theSKRoundRectinstance it was built from, becauseCreateBorderPathassigns a brand-newSKRoundRectwhenever the geometry changes β so reference identity is an exact key.
Measured impact π
| Workload | Metric | Before | After | Ξ |
|---|---|---|---|---|
render.full-paint |
alloc / frame | 519,107 B | 119,747 B | β76.9 % |
render.full-paint |
alloc / element / frame | 332.5 B | 76.7 B | β76.9 % |
render.full-paint |
Gen0 collections / 40 frames | 1 | 0 | β100 % |
render.full-paint |
time / frame | β | β | unchanged (noise) |
780 rounded Borders + 625 rounded Rectangles (1,561 elements), painted through
RenderTargetBitmap with 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 ShapeVisual LINQ 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.
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
Jen-Uno commentedon Sep 30, 2026
QA: closing out without a manual pass. The fix in #24230 ships with automated tests (
Given_CompositionGeometricClip.cs) that exercise the change.If you still see this behaviour on a build that includes that PR, please reopen or comment here.