Skip to content

perf(composition): Cache the rounded-clip paths - #24230

Merged
MartinZikmund merged 4 commits into
masterfrom
dev/mazi/perf-composition-clippath
Sep 25, 2026
Merged

MartinZikmund merged 4 commits into
masterfrom
dev/mazi/perf-composition-clippath

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #24221

PR Type:

🔄 Refactoring (no functional changes, no api changes)

What changed? 🚀

Two places handed out a brand-new native SKPath on every frame for every rounded visual, because SKPathBuilder.Detach() transfers ownership into a new path:

  1. RectangleClip.GetClipPath — Visual.Render asks for the post-painting clip several times per visual per frame. The path depends only on the clip's own properties (GetBoundsCore ignores the visual, GetBounds applies the clip's own TransformMatrix), so it is now built once and dropped by OnPropertyChangedCore, 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.
  2. BorderVisual.GetPrePaintingClipping — allocated both an SKPathBuilder and an SKPath per rounded border per frame. Now cached and keyed on the SKRoundRect instance it was built from; CreateBorderPath assigns 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 old using provided, and the path never escapes the call.

RectangleClip was the odd one out among the clips — InsetClip already caches its path and CompositionGeometricClip reuses a static spare.

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.

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 ✅

  • 🧪 Added Runtime tests, UI tests, or a manual test sample (for bug fixes / features, if applicable)
  • 📚 Docs have been added/updated following the documentation template (for bug fixes / features) — n/a, no API or behaviour change for app authors
  • 🖼️ Validated PR Screenshots Compare Test Run results. — to check once CI has run
  • ❗ Contains NO breaking changes
  • 👀 Reviewed 2 other open pull requests (optional but appreciated!)

Copilot AI lite review requested due to automatic review settings August 27, 2026 07:19
@github-actions github-actions Bot added the area/skia ✏️ Categorizes an issue or PR as relevant to Skia label Aug 27, 2026
@github-actions

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 0s —— View job


I'll analyze this and get back to you.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 the SKRoundRect instance 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.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 230528 found UI Test snapshots differences: skia-linux-screenshots: 73, skia-windows-screenshots: 220

Details
  • skia-linux-screenshots: 73 changed over 2366

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ElementLevelTheme.png-dark
    • ExpanderColorValidationPage.png-dark
    • ElementLevelTheme.png
    • ExpanderColorValidationPage.png
    • Examples.png
    • Focus_FocusVisual_Properties.png-dark
    • ImageBrush_Stretch.png
    • Attributed_text_FontSize_Changing.png
    • Buttons.png
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • DynamicFont.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ContextRequested.png-dark
  • skia-windows-screenshots: 220 changed over 2368

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • DisplayInformation.png-dark
    • Dopes.png-dark
    • Gamepad_CurrentReading.png-dark
    • Gamepad_Enumeration.png-dark
    • Grid_def_MinMaxValues.png-dark
    • Grid_def_MinMaxValues.png
    • ImageAlignment2541.png-dark
    • ImageAlignment2541.png
    • EllipsemaskingEllipseGrid.png-dark
    • Examples.png
    • BitmapImage_vs_SvgImageSource.png-dark
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • Clipping652.png-dark
    • Clipping652.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • EllipseAlignment2542_2547.png-dark

@MartinZikmund
MartinZikmund force-pushed the dev/mazi/perf-composition-clippath branch from 74e9231 to b548634 Compare August 29, 2026 10:11
@unodevops

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 0s —— View job


I'll analyze this and get back to you.

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 231008 found UI Test snapshots differences: skia-linux-screenshots: 73, skia-windows-screenshots: 219

Details
  • skia-linux-screenshots: 73 changed over 2366

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • DropDownButtonPage.png-dark
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • DynamicFont.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • ContextRequested.png-dark
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • ImageBrush_Stretch.png
    • ImageIconPage.png-dark
    • ImageIconPage.png
    • Buttons.png
    • Image_Margin_Large.png
    • Attributed_text_FontSize_Changing.png
    • CalendarView_Theming.png-dark
    • ContentControl_Inheritance.png
  • skia-windows-screenshots: 219 changed over 2368

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • ContentPresenter_Padding.png-dark
    • ContentPresenter_Padding.png
    • DataTransferManager.png-dark
    • DataTransferManager.png
    • EmailManagerTests.png-dark
    • EmailManagerTests.png
    • GetFocus.png-dark
    • GetFocus.png
    • Grid_ScrollViewer.png-dark
    • Grid_ScrollViewer.png
    • GeolocatorPositionChanged.png
    • BitmapImage_vs_SvgImageSource.png
    • ExpanderColorValidationPage.png-dark
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • HyperlinkButton_IsEnabled_Automated.png-dark
    • HyperlinkButton_IsEnabled_Automated.png
    • DisplayInformation.png-dark

@MartinZikmund
MartinZikmund changed the base branch from feature/breakingchanges to master September 2, 2026 20:01
@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 231678 found UI Test snapshots differences: skia-linux-screenshots: 57, skia-windows-screenshots: 2310, wasm: 11

Details
  • skia-linux-screenshots: 57 changed over 2348

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • DisplayInformation.png-dark
    • Examples.png-dark
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • ImageIconPage.png-dark
    • Buttons.png-dark
    • Buttons.png
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • Gamepad_Enumeration.png
    • ClipboardTests.png-dark
    • ContextRequested.png-dark
    • ContextRequested.png
    • CalendarView_Theming.png-dark
  • skia-windows-screenshots: 2310 changed over 2402

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AppBar_KeyBoard.png
    • AppWindowFeatures.png
    • AppWindowPresenters.png
    • AppXamlDefinedResources.png-dark
    • Attributed_text_FontSize_Changing.png-dark
    • AutoBorderStretchwithtopmargin.png-dark
    • AutoSuggestBox_BitmapIcon.png-dark
    • BasicAcrylicBrushTest.png-dark
    • BorderTopwithmargins.png-dark
    • BorderTopwithmargins.png
    • Border_CornerRadius.png-dark
    • Border_CornerRadius.png
    • Border_LinearGradientBrush.png
    • Border_Simple.png-dark
    • Border_With_ScaleTransform.png-dark
    • Border_With_ScaleTransform.png
    • CalendarDatePicker_Basics.png-dark
    • CalendarDatePicker_Basics.png
    • CheckBox_IsEnabled_Automated.png-dark
    • CheckBox_IsEnabled_Automated.png
  • wasm: 11 changed over 1076

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • UITests.Windows_UI_Xaml_Media_Animation.ColorAnimation_Background
    • SamplesApp.Wasm.Windows_UI_Xaml_Controls.ListView.ListView_IsSelected
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Minimal
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • UITests.Windows_UI_Xaml_Controls.CalendarView.CalendarView_Theming
    • UITests.Uno_Web.Http.CookieManagerTests
    • UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.WinUIExpanderPage
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewSelectedItems
    • UITests.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_NavigationProperties
    • Uno.UI.Samples.Content.UITests.WebView.WebView_AnchorNavigation
    • SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_EnableDevTools

@morning4coffe-dev morning4coffe-dev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

MartinZikmund and others added 2 commits September 24, 2026 17:24
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
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/perf-composition-clippath branch from b548634 to 9726017 Compare September 24, 2026 15:25
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 6m 36s —— View job


Review complete

  • Gather context (PR diff, AGENTS.md rules, prior review feedback)
  • Review RectangleClip.skia.cs changes
  • Review BorderVisual.skia.cs changes
  • Check disposal/lifetime concerns raised by previous reviewers
  • Post inline comments for confirmed findings
  • Post summary

Verdict: no blocking issues

Note on prior review comments: the Copilot and @morning4coffe-dev reviews (from late Aug / early Sep) were flagging missing Dispose() calls on cached SKPath instances. The code has since been rewritten to build on the repo's IGeometry/DrawingResource reference-counted resource model (AddRef/Release/Dispose, see IDrawingResource.cs) instead of raw SKPath. I traced the ref-counting through both files and their callers (CompositionClip.ApplyClip, Visual.IntersectOwned, GetTotalClipPath) — every AddRef is matched by a Release, and the cache's own creation reference is correctly dropped in RectangleClip.OnPropertyChangedCore / BorderVisual.GetOrBuildPrePaintingRoundRectGeometry. This exactly mirrors the existing, already-merged InsetClip.GetClipPath caching pattern, which also has no DisposeInternal override — so the earlier disposal concern no longer applies to the current diff; it was valid for a prior implementation that's no longer here.

BorderVisual's cache key also improved from the PR description's "keyed on the SKRoundRect instance" to value-equality on the RoundRectangle readonly record struct, which is more robust than reference-identity keying.

Findings (2, both low-severity / non-blocking)

  1. RectangleClip.skia.cs:48 — _clipPath invalidation relies on every mutation routing through SetProperty → OnPropertyChangedCore. That holds today, but it's an implicit invariant rather than a self-healing one — unlike sibling InsetClip.GetClipPath, which recomputes and value-compares bounds on every call. If RectangleClip ever gains a SetAnimatableProperty override (to make Left/Top/etc. actually animatable, which they currently aren't), that path would bypass the cache invalidation silently.
  2. RectangleClip.skia.cs:26 — no runtime test exercises the cache-invalidation invariant this PR introduces. Existing tests (Given_Visual_Damage.cs) always swap in a new RectangleClip rather than mutating one instance's properties in place, so none would catch a regression in the caching/invalidation logic itself.

Cross-cutting notes (not inline findings)

  • The PR description/title still talk about caching SKPath via SKPathBuilder.Detach(), but the current diff is a IGeometry/GeometryFactory implementation — the description looks like it predates a rebase onto the newer drawing-abstraction refactor on master. Worth updating the PR body before merge so the measured-impact narrative matches what's actually being merged (the perf numbers may still be representative, but the mechanism described no longer matches the code).
  • Commit messages (perf(composition): ...) are correctly Conventional-Commits formatted.
  • Style (tabs, Allman braces, #nullable enable) all check out in both files.

Validation performed: code review by inspection only (traced ref-counting call chains, checked DrawingResource/IDrawingResource semantics, compared against InsetClip's established pattern, checked SetAnimatableProperty override presence). I did not compile or run tests in this session — the PR's own before/after runtime-test comparison (671 run, 0 new failures) is the available runtime evidence.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 235521 found UI Test snapshots differences: skia-linux-screenshots: 57, skia-windows-screenshots: 2310, wasm: 11

Details
  • skia-linux-screenshots: 57 changed over 2348

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • Buttons.png-dark
    • Buttons.png
    • DisplayInformation.png-dark
    • ContextRequested.png-dark
    • ContextRequested.png
    • Focus_FocusVisual_Properties.png-dark
    • Examples.png-dark
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • ElementLevelTheme.png-dark
    • ExpanderColorValidationPage.png
    • ElementLevelTheme.png
    • ImageIconPage.png-dark
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
  • skia-windows-screenshots: 2310 changed over 2498

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AppWindowClosing.png-dark
    • ArcSegment.png-dark
    • AuthenticationBroker_Demo.png-dark
    • AutoBorderStretchwithrightmargin.png-dark
    • AutoSizedPathCentered.png
    • AutoSuggestBox_Keyboard.png-dark
    • BackGesture.png
    • BasicAcrylicBrushTest.png
    • BitmapIcon_Foreground.png-dark
    • BitmapIcon_Foreground.png
    • BorderVersusPanelClipping.png-dark
    • BorderVersusPanelClipping.png
    • Border_BorderThickness.png-dark
    • Border_BorderThickness.png
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png
    • Border_Corner_Overlap.png-dark
    • Border_Corner_Overlap.png
    • Border_Simple_with_Uniform_Thickness.png-dark
    • Border_Simple_with_Uniform_Thickness.png
  • wasm: 11 changed over 1076

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • SamplesApp.Wasm.Windows_UI_Xaml_Controls.ListView.ListView_IsSelected
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewSelectedItems
    • SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_EnableDevTools
    • UITests.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_NavigationProperties
    • UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.WinUIExpanderPage
    • UITests.Uno_Web.Http.CookieManagerTests
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Minimal
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • UITests.Windows_UI_Xaml_Controls.CalendarView.CalendarView_Theming
    • UITests.Windows_UI_Xaml_Media_Animation.ColorAnimation_Background
    • Uno.UI.Samples.Content.UITests.WebView.WebView_AnchorNavigation

@MartinZikmund

Copy link
Copy Markdown
Member Author

@mergify backport release/stable/6.7

@mergify

mergify Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

backport release/stable/6.7

✅ Backports have been created

Details

Cherry-pick of 2f505dc has failed:

On branch mergify/bp/release/stable/6.7/pr-24230
Your branch is up to date with 'origin/release/stable/6.7'.

You are currently cherry-picking commit 2f505dc.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/Uno.UI.Composition/Composition/RectangleClip.skia.cs

no changes added to commit (use "git add" and/or "git commit -a")

Cherry-pick of 9726017 has failed:

On branch mergify/bp/release/stable/6.7/pr-24230
Your branch is ahead of 'origin/release/stable/6.7' by 1 commit.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit 9726017.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/Uno.UI.Composition/Composition/BorderVisual.skia.cs

no changes added to commit (use "git add" and/or "git commit -a")

Cherry-pick of c9e1c91 has failed:

On branch mergify/bp/release/stable/6.7/pr-24230
Your branch is ahead of 'origin/release/stable/6.7' by 2 commits.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit c9e1c91.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   src/Uno.UI.Composition/Composition/BorderVisual.skia.cs

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/Uno.UI.Composition/Composition/RectangleClip.skia.cs

Cherry-pick of 7bed8f0 has failed:

On branch mergify/bp/release/stable/6.7/pr-24230
Your branch is ahead of 'origin/release/stable/6.7' by 3 commits.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit 7bed8f0.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   src/Uno.UI.RuntimeTests/Tests/Windows_UI_Composition/Given_CompositionGeometricClip.cs

no changes added to commit (use "git add" and/or "git commit -a")

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

@MartinZikmund

Copy link
Copy Markdown
Member Author

@mergify backport servicing/6.8

@mergify

mergify Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

backport servicing/6.8

✅ Backports have been created

Details

Cherry-pick of 2f505dc has failed:

On branch mergify/bp/servicing/6.8/pr-24230
Your branch is up to date with 'origin/servicing/6.8'.

You are currently cherry-picking commit 2f505dc.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/Uno.UI.Composition/Composition/RectangleClip.skia.cs

no changes added to commit (use "git add" and/or "git commit -a")

Cherry-pick of 9726017 has failed:

On branch mergify/bp/servicing/6.8/pr-24230
Your branch is ahead of 'origin/servicing/6.8' by 1 commit.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit 9726017.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/Uno.UI.Composition/Composition/BorderVisual.skia.cs

no changes added to commit (use "git add" and/or "git commit -a")

Cherry-pick of c9e1c91 has failed:

On branch mergify/bp/servicing/6.8/pr-24230
Your branch is ahead of 'origin/servicing/6.8' by 2 commits.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit c9e1c91.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   src/Uno.UI.Composition/Composition/BorderVisual.skia.cs

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/Uno.UI.Composition/Composition/RectangleClip.skia.cs

Cherry-pick of 7bed8f0 has failed:

On branch mergify/bp/servicing/6.8/pr-24230
Your branch is ahead of 'origin/servicing/6.8' by 3 commits.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit 7bed8f0.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   src/Uno.UI.RuntimeTests/Tests/Windows_UI_Composition/Given_CompositionGeometricClip.cs

no changes added to commit (use "git add" and/or "git commit -a")

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]>
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 2m 59s —— View job


Review complete

  • Gather context (PR diff, AGENTS.md rules, prior review feedback)
  • Review RectangleClip.skia.cs changes
  • Review BorderVisual.skia.cs changes
  • Review new test Given_CompositionGeometricClip.cs
  • Check whether prior findings (disposal, cache-invalidation invariant, test coverage) were addressed
  • Post inline comments for confirmed findings
  • Post summary

Verdict: no blocking issues

This sync added two commits (c9e1c917, 7bed8f05) since the previous review pass, and together they resolve all three previously open findings — I traced each one against the current code rather than taking the commit messages at their word:

  1. Disposal (Copilot, morning4coffe-dev): both RectangleClip and BorderVisual now override DisposeInternal() and Release() their cached geometry before calling base.DisposeInternal(). Correct ref-count symmetry with the AddRef() done in each getter.
  2. Cache-invalidation invariant (previous Claude pass): RectangleClip.GetClipPath no longer relies on OnPropertyChangedCore at all — it recomputes GetClipRoundedRect(visual) on every call and value-compares against the cached RoundRectangle (a readonly record struct, so != is a real field-by-field compare, not reference identity). This is now self-healing exactly like the sibling InsetClip.GetClipPath, so the concern about a future SetAnimatableProperty override silently bypassing invalidation no longer applies — there's no hook left to bypass.
  3. Test coverage gap (previous Claude pass): When_Rounded_Rectangle_Clip_Mutated_In_Place creates a single RectangleClip, reads GetClipPath, mutates Left and BottomRightRadius on the same instance, and asserts the new bounds/corner via FillContains — this is precisely the red/green case the caching change needed and no existing test covered.

BorderVisual's GetOrBuildPrePaintingRoundRectGeometry cache follows the identical pattern (value-keyed on RoundRectangle, ref-counted, released in DisposeInternal).

Cross-cutting note (non-blocking)

InsetClip.skia.cs uses the same value-keyed cache pattern this PR now uses everywhere else, but it still has no DisposeInternal override to release its cached _clipPath — that's pre-existing code, not touched by this diff, so not a finding against this PR, but worth a follow-up now that the other two clips establish the correct pattern.

Validation performed: code review by inspection — read the full current content of both .skia.cs files and the new test, diffed the fix commit (c9e1c917) against the version reviewed previously, confirmed RoundRectangle/Rect have proper value-equality members (not boxing reflection fallback), and checked for conflicting DisposeInternal overrides in the class hierarchy (none). Did not compile or run tests in this session.

@MartinZikmund

Copy link
Copy Markdown
Member Author

@morning4coffe-dev Thanks — both lifetime gaps are closed in c9e1c91. RectangleClip and BorderVisual now release their cached paths in DisposeInternal. Invalidation was already releasing the old path. The RectangleClip cache is now keyed by value on its round rect, so it can't go stale whichever way a property changes, animation included. 7bed8f0 adds a runtime test that mutates one clip in place.

@MartinZikmund

Copy link
Copy Markdown
Member Author

🤖 Addressed PR comments up to this point

  • @morning4coffe-dev (review): cached-path lifetime on invalidation and dispose — Fixed in c9e1c91, test in 7bed8f0
  • Copilot and claude review threads (4) — replied inline and resolved
  • UI snapshot diff reports and @mergify backport commands — no action needed

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 235596 found UI Test snapshots differences: skia-linux-screenshots: 57, skia-windows-screenshots: 2310, wasm: 11

Details
  • skia-linux-screenshots: 57 changed over 2348

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ClipboardTests.png-dark
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • Focus_FocusVisual_Properties.png-dark
    • Examples.png-dark
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • Gamepad_Enumeration.png
    • DisplayInformation.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • ContextRequested.png-dark
  • skia-windows-screenshots: 2310 changed over 2500

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png-dark
    • AppBarButtonTest.png
    • ApplicationViewMode.png
    • AppWindowFeatures.png
    • ArcSegment.png
    • AuthenticationBroker_Demo.png-dark
    • AutoBorderStretchwithleftmargin.png
    • AutomationProperties_AutomationId.png-dark
    • AutoSuggestBoxChosenSuggestion.png-dark
    • AutoSuggestBoxChosenSuggestion.png
    • AutoSuggestBox_Keyboard.png-dark
    • AutoSuggestBox_Keyboard.png
    • BasicAutoSuggestBox.png-dark
    • BasicAutoSuggestBox.png
    • BasicThemeResources.png-dark
    • BasicThemeResources.png
    • BitmapIcon_Foreground.png-dark
    • BitmapIcon_Foreground.png
    • BorderRightwithmargins.png-dark
    • BorderRightwithmargins.png
  • wasm: 11 changed over 1076

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewSelectedItems
    • SamplesApp.Wasm.Windows_UI_Xaml_Controls.ListView.ListView_IsSelected
    • UITests.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_NavigationProperties
    • UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.WinUIExpanderPage
    • SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_EnableDevTools
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Minimal
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • UITests.Windows_UI_Xaml_Controls.CalendarView.CalendarView_Theming
    • UITests.Windows_UI_Xaml_Media_Animation.ColorAnimation_Background
    • UITests.Uno_Web.Http.CookieManagerTests
    • Uno.UI.Samples.Content.UITests.WebView.WebView_AnchorNavigation

@MartinZikmund
MartinZikmund merged commit 76bfc57 into master Sep 25, 2026
55 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/perf-composition-clippath branch September 25, 2026 14:32
@mergify

mergify Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

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.

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

Labels

area/skia ✏️ Categorizes an issue or PR as relevant to Skia

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

6 participants