Skip to content

perf(composition): Thread damage clip as bounds, not paths (6.7) - #24789

Merged
agneszitte merged 3 commits into
release/stable/6.7from
dev/mazi/67-scroll-damage-rects
Nov 3, 2026
Merged

agneszitte merged 3 commits into
release/stable/6.7from
dev/mazi/67-scroll-damage-rects

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #23984

PR Type:

🐞 Bugfix (performance regression)

What changed? 🚀

#24582 backported part of #23986 to 6.7. Scroll frames still ran path booleans for every visual, because the clip was threaded through the render walk as an SKPath:

  • Visual.Render intersected each visual's accumulated clip with SKPath.Op.
  • Under a rounded ancestor clip (every Fluent Button), the clip isn't a rect. Each moved visual's damage then went through a stroke outset, a path intersect and a DamageRegion.Union path boolean.

Damage only uses clip bounds, so this threads a root-space SKRect through the walk and has TryGetPaintDamageRegion contribute rects only. It ports the intent of master's 74afcfc and dbb62a5 to the SKPath-based compositor on this branch. The rect is always a superset of the exact region, so damage can only widen, never miss.

The old exact branch also stored each visual's content path; that field is dropped. Clip caching from #24230 was measured too and is under 3% of the frame here, so it isn't part of this fix. The mergify backports of #24230 (#24697/#24698) were closed.

Measurements 📊

ItemsRepeater + UniformGridLayout, 2,837 Fluent Button tiles, ChangeView in 60 steps of 40 px, repeated 12 times. Skia Win32 at 250%. dotnet-trace dotnet-sampled-thread-time on the UI thread:

UI-thread render UI-thread total
6.5.237 (reference) 157 ms 839 ms
6.7 head, before 2153 ms 3480 ms
6.7 head, this PR 355 ms 1612 ms

Managed allocation is unchanged (~1.1 MB per 60 steps, no Gen0 GCs); this is CPU only. The remaining gap is mostly Win32 accessibility (#24784, separate PR) and layout.

PR Checklist ✅

Validation

  • Runtime (Skia Win32, local): Given_Visual_Damage 3/3, including the new When_Visual_Moves_Under_Rounded_Clip_Then_Old_And_New_Areas_Are_Damaged. A composition/Border/ScrollViewer/ItemsRepeater/RenderTargetBitmap sweep passed apart from 4 Given_ScrollViewer layout asserts that fail only at non-100% display scale (175 vs 175.2); those are pre-existing and unrelated.
  • Compile: Uno.UI.Composition.Skia built without UnoFastDevBuild, so analyzers ran.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AzHtsXz33DcziPre7h3b9f

@github-actions github-actions Bot added the area/skia ✏️ Categorizes an issue or PR as relevant to Skia label Sep 28, 2026
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 4m 16s —— View job


Review: perf(composition) — Thread damage clip as bounds, not paths

Verdict: ship — 2 nits, no blockers.

  • Gather context
  • Read changed files
  • Analyze correctness and performance implications
  • Post inline findings
  • Post summary

Overall assessment

The change is correct and clean. Swapping SKPath clip propagation for SKRect bounds eliminates O(n) SKPath.Op(Intersect) calls per visual per frame — exactly the right root-cause fix for the scroll performance regression. The superset-is-safe argument ("damage can only widen, never miss") is sound: over-reporting damage forces extra pixels to repaint but can never cause a stale region to survive.

Correctness checks

Clip accumulation (Visual.skia.cs:485, 491): toRoot.MapRect(preClip.Bounds) and toRoot.MapRect(postClip.Bounds) correctly map local-space clip path bounding boxes to root space before intersecting. Under a rotation, MapRect returns the axis-aligned bounding box of the transformed rect — a superset of the exact mapped path — which is acceptable for damage.

Empty-clip short-circuit (Visual.Damage.skia.cs:72): when clipBounds is zero-width or zero-height (e.g., a fully clipped-away visual), TryGetPaintDamageRegion returns false immediately. The caller then falls back to reporting the previous render bounds if any (_hasLastRenderBounds), which is correct — the visual disappearing still needs to erase where it was.

Old-location damage (Visual.Damage.skia.cs:51-53): when a visual moves, _lastRenderBounds holds the previous frame's computed rect and is unioned into damage. The new test (When_Visual_Moves_Under_Rounded_Clip_*) verifies both the vacated area and the newly covered area are marked, and that no spurious rect between them is reported.

Removed _ownContentPath: dropping the per-visual cached content path is safe because the exact branch was only ever a tighter approximation of the bounding-box path that replaced it — and the cases where it fired (_ownContentPath is { IsEmpty: false } and ShadowState is null) already have their bounds covered by TryGetLocalContentBounds.

_lastClipBounds initialization: starts as default (all-zero SKRect). On the first paint, any real clip will differ, so clipChanged is correctly forced true. No off-by-one on first frame.

Findings (2 nits, 0 blockers)

Severity File Finding
Nit Visual.Damage.skia.cs:104 clipped.Width <= 0 || clipped.Height <= 0 vs local.IsEmpty four lines above — same semantics, different style; use clipped.IsEmpty
Nit Given_Visual_Damage.cs:143 #if !__SKIA__ on [Ignore] works, but [PlatformCondition] is the preferred pattern per runtime-test rules; pre-existing in the file so not a new regression

Validation evidence

  • Code review (by inspection): correct.
  • Compile: PR description states Uno.UI.Composition.Skia was built without UnoFastDevBuild — analyzers ran clean.
  • Runtime: Given_Visual_Damage 3/3 (incl. the new test) on Skia Win32, per PR description.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 235991 did not find any UI Test snapshots differences.

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 235991 has failed on Uno.UI - CI.

MartinZikmund and others added 2 commits October 3, 2026 10:50
Every visual on every scroll frame intersected its accumulated clip as an
SKPath, and under a rounded ancestor clip (any Fluent Button) its damage
contribution went through an exact path region: a stroke outset, a path
intersect and a DamageRegion.Union boolean. Damage only needs bounds, so
thread a root-space rect through the render walk and contribute rects,
matching master (74afcfc, dbb62a5). The rect is a superset of the
exact region, so this only widens damage.

ItemsRepeater grid of 2837 Fluent Buttons, 12 x 60 scroll steps, UI-thread
render time: 2374 ms -> 338 ms (6.5.237: 157 ms).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AzHtsXz33DcziPre7h3b9f
Copilot AI balanced review requested due to automatic review settings October 3, 2026 08:50
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/67-scroll-damage-rects branch from 87cff29 to facb7a7 Compare October 3, 2026 08:50

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Improves Skia compositor performance during scrolling by threading clip bounds (rects) through the render walk instead of performing per-visual clip path booleans, and updates damage computation accordingly.

Changes:

  • Switch render traversal from SKPath clip propagation to SKRect clip-bounds propagation.
  • Simplify damage region computation to rect-only unioning based on clip bounds.
  • Add a runtime test ensuring moved visuals under rounded clips damage both old and new areas without over-damaging untouched regions.
File Description
src/​Uno.UI.RuntimeTests/​Tests/​Windows_UI_Composition/​Given_Visual_Damage.cs Adds a regression test for damage correctness when moving under a rounded ancestor clip.
src/​Uno.UI.Composition/​Composition/​Visual.skia.cs Replaces per-visual clip path intersection with rect-bounds intersection during render traversal.
src/​Uno.UI.Composition/​Composition/​Visual.Damage.skia.cs Converts damage calculation to rect-only based on clip bounds; removes content-path caching and path boolean operations.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

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


Review: perf(composition) — Thread damage clip as bounds, not paths (6.7)

Verdict: ship — 1 actionable nit.

  • Read changed files
  • Analyze correctness
  • Post inline findings
  • Post summary

Overall assessment

The change is correct and well-scoped. Swapping SKPath clip propagation for SKRect bounds eliminates O(n) SKPath.Op(Intersect) calls per visual per frame — the right root-cause fix for the scroll regression. The superset-is-safe argument is sound: over-reporting damage forces extra pixels to repaint but never lets a stale region survive.

Correctness checks

Clip accumulation (Visual.skia.cs:485, 491): toRoot.MapRect(preClip.Bounds) and toRoot.MapRect(postClip.Bounds) correctly map local-space clip path bounding boxes to root space before intersecting with the inherited rect. Under rotation, MapRect returns the axis-aligned bounding box of the transformed rect — a sound superset for damage.

Empty-clip short-circuit (Visual.Damage.skia.cs:72): Width <= 0 || Height <= 0 is correctly wider than SKRect.IsEmpty (which only matches the all-zero rect) — the author's explanation is accurate. Same reasoning applies to line 104.

Old-location damage (Visual.Damage.skia.cs:51-53): _lastRenderBounds from the previous frame is unioned into damage when the visual moves. The new test verifies both the vacated and the newly covered areas are reported.

_lastClipBounds initialization: starts as default (all-zero SKRect). Any real clip differs, so clipChanged is correctly forced true on the first frame.

Inline finding

One finding posted inline — CS1998 on the new test method (Given_Visual_Damage.cs:145). The #if __SKIA__ branch is synchronous but the method is declared async Task, which the compiler flags as CS1998. If the test project builds without UnoFastDevBuild (the CI configuration), this warning is promoted to an error. The same pattern exists in the two pre-existing tests in the class; fixing all three at once would be cleanest. Minimal fix: add await Task.CompletedTask; at the end of each #if __SKIA__ block.

The two nits from the previous review round (clipped.IsEmpty style and #if vs [PlatformCondition]) were addressed by the author with sound justifications — no further action needed there.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 237185 did not find any UI Test snapshots differences.

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 237185 has failed on Uno.UI - CI.

@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.

Verified: the rect-only damage path matches master 74afcfc and dbb62a5. The clip is threaded as an SKRect through Visual.Render, TryGetPaintDamageRegion uses clip bounds only, and the rect is a superset of the exact region. Clip bounds are used only for damage, and canvas.ClipPath is unchanged, so drawing is not affected. The new rounded-clip test checks both the vacated and newly covered areas.

Findings, ranked:

  1. Incomplete port relative to the 6.8 backport (#24788). Master 485d370 ("drop dead own-content-path build on paint") removes the per-paint content path build. This PR drops the _ownContentPath field but keeps the producers. BorderVisual.skia.cs Paint still ends with return BuildOwnContentPath();, ShapeVisual.skia.cs does the same, and Visual.skia.cs discards the result (visual.Paint(session);). Every repaint of a Border or Shape still rebuilds an SKPath that nothing reads. #24788 changes those returns to null and deletes BuildOwnContentPath and _ownContentPathBuffer. Please port the same change so 6.7 matches 6.8 and the measured win is not partly spent on dead work.
  2. The PR body says the per-visual content path is "dropped". That is true of the damage path only, and is misleading until item 1 is fixed.
  3. Informational, not a regression: current master's TryGetPaintDamageRegion also outsets the clip rect for antialiasing (clipRect = OutsetForAntialiasing(clipRect)). This port does not. Pre-PR 6.7 rect clips behaved the same way, so this is faithful to 74afcfc but not to current master. Worth a follow-up decision.

Validation: code review and master comparison only. I did not build or run tests. The runtime results in the PR body are the author's.

@agneszitte

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

Keeps both new damage tests in Given_Visual_Damage.cs: uno#24793's SKCanvasVisual
test and this PR's rounded-clip test, in the same order as servicing/6.8.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @agneszitte's task in 3m 55s —— View job


Review: perf(composition) — Thread damage clip as bounds, not paths (6.7)

Verdict: fix-first — 1 CI-blocking error, 1 nit, 1 incomplete-port note.

  • Read changed files
  • Analyze correctness and open findings from prior rounds
  • Post inline findings
  • Post summary

Overall assessment

The core change is correct and well-scoped. Threading SKRect bounds instead of SKPath through the render walk eliminates O(n) SKPath.Op(Intersect) calls per visual per frame — the right root-cause fix for the 6.7 scroll regression. The superset-is-safe argument is sound: over-reporting damage forces extra pixels to repaint but can never let a stale region survive. The _lastClipBounds initialization (default all-zero) correctly forces clipChanged = true on the first frame.

Findings

1 — CI-blocking (CS1998) → Given_Visual_Damage.cs:172

When_Visual_Moves_Under_Rounded_Clip_Then_Old_And_New_Areas_Are_Damaged is declared async Task but the #if __SKIA__ compilation branch contains no await. CS1998 is promoted to an error in CI (where UnoFastDevBuild is off). This is the most likely cause of the Oct 3 CI failure (build 237185). Fix: add await Task.CompletedTask; as the last statement inside the #if __SKIA__ block. The two pre-existing tests in the class have the same pattern and should be fixed at the same time.

2 — Nit (stale doc) → Visual.skia.cs:550

The <returns> doc comment on Paint still claims the returned SKPath is "used as its damage-region content path" and "the caller caches this alongside the recorded picture." Both are now false — both visual.Paint(...) call sites in PaintStep discard the return value. The doc should be updated or the return type simplified to void once BorderVisual/ShapeVisual complete the port.

3 — Incomplete port (out-of-diff, not blocking this merge)

As noted by morning4coffe-dev: BorderVisual.skia.cs and ShapeVisual.skia.cs still return BuildOwnContentPath() from Paint(), and Visual.skia.cs now discards that value. Every repaint of a Border or Shape still builds an SKPath that nothing reads. Master's full port (#24788) sets those returns to null and deletes BuildOwnContentPath. This isn't a regression relative to 6.7 head (the path was always built), but it leaves measured performance on the table until a follow-up backports #24788.

Validation evidence

  • Code review (by inspection): correctness confirmed.
  • Compile: PR body states Uno.UI.Composition.Skia built without UnoFastDevBuild — analyzers ran clean.
  • Runtime: Given_Visual_Damage 3/3 on Skia Win32 per PR body; CI builds 235991 and 237185 failed (likely CS1998).

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@agneszitte
agneszitte merged commit 26e3fce into release/stable/6.7 Nov 3, 2026
23 of 42 checks passed
@agneszitte
agneszitte deleted the dev/mazi/67-scroll-damage-rects branch November 3, 2026 07:28
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.

7 participants