Skip to content

[Skia] Rounded clips rebuild a native SKPath on every frameΒ #24221

Closed

Description

@MartinZikmund

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:

  1. RectangleClip.GetClipPath resets a shared SKPathBuilder and returns builder.Detach() β€” and Detach() transfers ownership into a new SKPath. Visual.Render asks for the post-painting clip several times per visual per frame.
  2. BorderVisual.GetPrePaintingClipping calls BuildRoundRectPath, which allocates both a new SKPathBuilder and a new SKPath, 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 β€” GetBoundsCore ignores the visual argument and GetBounds applies the clip's own TransformMatrix β€” so an OnPropertyChangedCore override drops it when any property changes, making the hot path a single null check. Every mutation reaches that hook: the setters go through SetProperty, the CreateRectangleClip overloads use object initialisers, and RectangleClip does not override SetAnimatableProperty, so animations never touch these fields.
  • BorderVisual's path can be keyed on the SKRoundRect instance it was built from, because CreateBorderPath assigns a brand-new SKRoundRect whenever 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

  1. added
    triage/untriaged
    on Aug 27, 2026
  2. Jen-Uno commented on Sep 30, 2026

    @Jen-Uno
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

triage/untriaged

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions