Repository navigation
perf(scroll): Make scroll-frame damage O(1) per moved visual - #23986
Conversation
|
Claude finished @MartinZikmund's task in 8m 5s —— View job Review
Verdict: fix-first (minor blockers) The optimization is sound. The core invariant — a moved-only visual takes 4 issues posted inline (3 low, 1 medium):
Cross-cutting notes:
|
There was a problem hiding this comment.
Pull request overview
This PR refactors Skia damage accumulation during scroll to avoid per-visual Skia path boolean ops in the common “moved-only due to ancestor transform” case, by replacing the loose SKPath accumulator + extension methods with a dedicated DamageRegion accumulator type.
Changes:
- Introduce
DamageRegionto accumulate repaint regions efficiently (rect-append fast path + exact-geometry union when needed), and snapshot+clamp in one operation. - Plumb
DamageRegionthrough the Skia rendering pipeline (CompositionTarget→SkiaRenderHelper→Compositor→Visual), including a bounds-preference optimization for moved-but-unchanged visuals. - Remove the old
DamageRegionExtensions.skia.cshelpers previously extendingSKPath.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Uno.UI/UI/Xaml/Media/CompositionTarget.Rendering.skia.cs | Switch pending damage accumulator from SKPath to DamageRegion and snapshot+reset per frame. |
| src/Uno.UI/Helpers/SkiaRenderHelper.skia.cs | Update render entrypoint to pass DamageRegion down to composition rendering. |
| src/Uno.UI.Composition/Composition/Compositor.skia.cs | Update compositor render API to accept DamageRegion. |
| src/Uno.UI.Composition/Composition/Visual.skia.cs | Update root visual render path to propagate DamageRegion through painting sessions. |
| src/Uno.UI.Composition/Composition/Visual.Damage.skia.cs | Optimize damage contribution to prefer bounds for moved-only visuals and accept DamageRegion accumulator. |
| src/Uno.UI.Composition/Composition/Uno/Visual.PaintingSession.skia.cs | Change PaintingSession.Damage type from SKPath to DamageRegion. |
| src/Uno.UI.Composition/Composition/DamageRegion.skia.cs | New accumulator type implementing rect-append strategy + exact unions + clamped snapshotting. |
| src/Uno.UI.Composition/Composition/DamageRegionExtensions.skia.cs | Deleted: old SKPath extension-method-based accumulation strategy. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23986/wasm-skia-net9/index.html |
|
The build 226128 found UI Test snapshots differences: Details
|
|
|
69d5883 to
80cfa2b
Compare
|
Claude finished @MartinZikmund's task in 6m 29s —— View job Review
Verdict: fix-first This is the second pass over the same commit — none of the 4 issues from the first review have been addressed. The optimization logic itself remains sound, but two blockers still need resolution before this can merge: BlockersScreenshot regressions (requires investigation before merge)
Low / advisory (unchanged from first review)
Cross-cutting notes
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23986/wasm-skia-net9/index.html |
|
The build 226927 found UI Test snapshots differences: Details
|
80cfa2b to
68659d3
Compare
|
Claude finished @MartinZikmund's task in 4m 58s —— View job Review
Verdict: fix-first This is the third pass over the same commit — the code itself has not changed since the first review. The optimization logic remains sound, but the 3 code-level blockers from the prior passes are still open. BlockersScreenshot regressions — still unresolved
Low / advisory (unchanged from prior reviews)
Cross-cutting notes (no change)
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23986/wasm-skia-net9/index.html |
|
The build 227806 found UI Test snapshots differences: Details
|
|
Claude finished @MartinZikmund's task in 2m 22s —— View job Review (pass 4)
Verdict: fix-first (1 blocker remaining) Three of the four previously-flagged issues have been resolved since the last review:
Remaining blocker
Screenshot regressions — still needs triageCI shows 73 Linux + 128 Windows screenshot diffs out of 2 366. The Windows count is still elevated (~5 % of the suite) and spans controls unrelated to scroll (
Cross-cutting notes (no change)The core O(1) invariant is correctly implemented. |
|
The build 228917 found UI Test snapshots differences: Details
|
5ffffb6 to
77c3d3f
Compare
|
Claude finished @MartinZikmund's task in 3m 20s —— View job Review (pass 6)
Verdict: ship pending screenshot triage No code changes since pass 5. The branch was rebased onto a newer Issue status
No new code-level issues found on this pass. The Screenshot regression count increased — needs triage before mergeThe latest build (228917) shows 73 Linux + 172 Windows diffs out of 2 368 — the Windows count rose from 118 (prior build 227977) to 172. A rebase onto updated Before merging, please confirm:
Once those two questions are answered (and assuming the diffs are baseline noise or intentional accuracy), the code is ready to merge. |
|
The build 229219 found UI Test snapshots differences: Details
|
77c3d3f to
a5dd826
Compare
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23986/wasm-skia-net9/index.html |
|
Claude finished @MartinZikmund's task in 2m 37s —— View job Review (pass 7)
Verdict: ship pending screenshot triage No commits have been added since pass 6. All four code-level issues from prior passes remain resolved. Issue status
No new code-level issues found in this pass. The Screenshot regressions — confirmation still needed before mergeLatest CI build (229219) shows 73 Linux + 172 Windows diffs out of 2 366. The Linux count is stable at ~73 across every build in this PR's history (74 → 74 → 73 → 73 → 73 → 73), and the failing tests span controls unrelated to scroll damage ( To confirm and unblock the merge:
Once those two questions are answered, the code is ready to merge. |
|
The build 229431 found UI Test snapshots differences: Details
|
Damage was accumulated by unioning SKPaths, so a frame that moves a large subtree paid a path union per visual. A scroll moves everything in the viewport at once, which is the worst case for that shape. Rects are now appended as contours to one builder under the nonzero fill rule, and collapse to their bounding rect past a small count -- past which the clip mask costs more than the pixels it saves. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_011w88LWryCBS83AzcTezBUM
SnapshotAndReset detaches the rect builder before the path ops that write the destination. A throw in between skipped Reset(), leaving _hasRects and _rectPoints describing rects the builder no longer held, so the next frame accumulated against stale bounds. Reset in a finally instead. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01GP2BeVCQzY3sQB7QBv173u
These files have no BOM on the base branch; the PR added one, producing an encoding-only first-line diff. New files keep the BOM, matching the prevailing convention in these folders. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01GP2BeVCQzY3sQB7QBv173u
preferBounds omits shadowSilhouetteChanged, which read as an oversight next to a comment saying "a visual that only moved". Note why the flag is inert: it implies ShadowState is not null, and the branch preferBounds steers away from is gated on ShadowState being null. Also drops a stray BOM. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01GP2BeVCQzY3sQB7QBv173u
canUseBounds hand-rolled the condition TryGetLocalContentBounds already answers, and got it wrong for every override of it: ShapeVisual bounds itself by its shapes but never sets PaintsWithinOwnSize, so every moving Shape kept paying the exact-geometry branch. Ask the method instead. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Ui9QEuDMfUesmJpp8aQAvM
Collapsing at a fixed contour budget fused whatever had accumulated into one bounding box, so a frame that scrolled and also damaged a far corner repainted everything between the two. Grow a running rect only while it costs no more than the incoming contribution, and open a new one otherwise; the budget stays as the backstop. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Ui9QEuDMfUesmJpp8aQAvM
Nothing reached the moved-but-unchanged path: moving a visual directly invalidates its paint, so only a moved ancestor gets there. Adds that setup plus the region's merge behaviour, including a still frame after the movement stops. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Ui9QEuDMfUesmJpp8aQAvM
a5dd826 to
4f39931
Compare
|
Claude finished @MartinZikmund's task in 5m 11s —— View job Review (pass 8)
Verdict: ship pending screenshot triage Three new commits have landed since pass 7 (all 2026-08-26):
Issue status (all code-level issues resolved)
Notes on the new code
One removed line worth noting: Tests are well-structured. The Screenshot regressions — still needs CI confirmationThe latest CI build before these commits (229431) showed 73 Linux + 179 Windows diffs. The three new commits — especially The 73 Linux count has been stable across every build in this PR's history, which remains consistent with baseline failures in Once the post-commit CI run clears (or shows the Windows count reducing toward the Linux baseline), this PR is ready to merge. |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23986/wasm-skia-net9/index.html |
|
The build 230359 found UI Test snapshots differences: Details
|
Porting the far-apart damage test from SKRect(l, t, r, b) to Rect kept the right/bottom values as width/height, so the scroll strips and the far corner were far larger than master's. Pass the real sizes. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01XsQppKuZgijApgJxaTZt81
GitHub Issue: closes #23984
Note
This is PR 1 of 2 in a stack. PR 2 (frame-clocked scroll motion) builds directly on this branch and targets it. This PR is independently reviewable and mergeable — it is a rendering change with its own failure mode, deliberately separated from scroll feel.
PR Type:
🐞 Bugfix
What changed? 🚀
Current behavior. During a scroll,
Visual.ContributeDamageOnPaintearly-outs only when!contentChanged && !moved && !shadowSilhouetteChanged.moved = matrix != _lastRenderMatrixis true for every visual in a scrolled subtree, so the early-out provably never fires. Each visual then pays, on the UI thread, insideRender():OutsetForAntialiasing—SKPaint.GetFillPath(stroke-to-fill) plusOp(Union)contentPath.Op(clipPath, SKPathOp.Intersect, contentPath)damage.Union(regionPath)against a monotonically growing accumulatordamage.UnionRect(_lastRenderBounds)— a nativeCreateRectPathallocation plus anotherOp(Union)For a
ListViewwith ~200 realized visuals that is roughly 800 Skia path booleans per frame, each more expensive than the last. And the result is degenerate: when everything moved, the union is the scroll port's clip rect — an O(1) answer computed in O(n) with the most expensive primitive available.This PR. Establishes the invariant:
The loose
SKPathdamage accumulator plus its extension methods (DamageRegionExtensions.skia.cs) is replaced by aDamageRegiontype that owns the accumulation strategy, so the O(1) translation case is expressible rather than emergent. Consumers (Compositor.RenderRootVisual,SkiaRenderHelper,CompositionTarget) move to the new type.PR Checklist ✅
Given_Visual_Damage— 7 tests, including the moved-then-stopped frame sequence, the Shape path, the merge behaviour, and a far-apart-damage regression test. Every new test was verified to fail against a deliberately broken build before being accepted.Screenshots Compare Test Runresults.Performance analysis
Measured, not estimated. Both implementations were extracted verbatim — "before" from
origin/feature/breakingchanges, "after" from this branch — and run side by side against the same SkiaSharp the framework ships.Method & environment
BenchmarkDotNet v0.15.8 · .NET 10.0.9 (X64 RyuJIT AVX-512) · Windows 11 · Intel Core i9-14900KF · SkiaSharp 4.151.1.
Workload models a virtualized list mid-scroll on a 1920×1080 frame: a 400×800 scroll port, N rows tiling it, an 8px scroll delta. Each moved visual contributes two rects — its new bounds and the bounds it vacated — which is what
ContributeDamageOnPaintactually does.These are microbenchmarks of the damage path in isolation, not end-to-end frame times: they measure the cost of deciding what to repaint, before any pixel is rasterized.
1. Per-visual damage — the cost this PR removes
One moved
BorderVisual(400×60 rounded rect, clipped to the port). Before, every moved visual ran a stroke-to-fill outset plus two path booleans; now it maps a rect.2. Frame damage accumulation
N moved visuals → 2N rect contributions, then the snapshot the frame is clipped to.
The old cost grows with the number of contributions because each
UnionRectallocates a nativeSKPath(viaCreateRectPath) and runsOp(Union)against a monotonically growing path. The new cost is dominated by a singleDetach()at snapshot time — 88 B per frame regardless of N.3. A whole frame, end to end
50 moved visuals: per-visual damage for each, accumulate, snapshot.
For scale: at 60 Hz the whole frame budget is 16.7 ms. Before this change, 1.85 ms — 11% of the budget — went to deciding what to repaint at 50 moved visuals, before drawing anything. At the ~200 realized visuals a
ListViewreaches, that extrapolates to roughly 7.4 ms, or 44% of the budget. At 67 KB of native-backed garbage per frame it is also ~4 MB/s of GC pressure at 60 fps, now ~5 KB/s.4. Is it safe? (does it ever repaint too little)
Under-damage is the one failure mode that matters here — it leaves stale pixels on screen. Swept 243 combinations of visual size × rasterization scale (1×, 1.5×, 2×) × sub-pixel offset, subtracting the reported bounds from the exact geometry the old code produced:
The bounds region is a strict superset in every case, at a cost of 1% more pixels. This is structural rather than lucky: a visual only takes the fast path when it can bound itself, and its bounds are inflated by 2px and snapped outward before clipping — the same outset the exact path applies.
Region quality against the true union, measured by rasterizing both:
Identical damage to the exact-union implementation in every case, and a pure scroll collapses to a single clip rect — Skia's analytic fast path, no clip mask.
5. What review changed
The first version of this PR collapsed to a bounding box once a fixed contour budget was exhausted (8 rects — only 4 moved visuals). That fused spatially unrelated damage. Sweeping one far-away contribution through all 101 arrival positions of a 50-visual scroll frame:
1,577,720 px on a 1920×1080 frame is 76% of the window repainted on a frame whose real damage was 16% — and it triggered on 96% of arrival orders. The accumulator now grows its open rect only while doing so costs no more than the incoming contribution already does, so far-apart damage keeps its own contour. The budget remains as a backstop.
Also fixed under review: the moved-visual fast path was gated on
PaintsWithinOwnSize, whichShapeVisualnever sets — so everyShapekept paying the 26 µs exact-geometry cost while scrolling. It now asksTryGetLocalContentBounds, the method that actually answers the question.Static analysis
dotnet-diag/analyzing-dotnet-performancescan over the damage path, before and after: no findings in either state — no LINQ, regex, string churn, boxing, closures, or async on this path. The cost centre is native Skia object churn and path booleans, quantified above.Validation
Uno.UI.Composition(net10.0) with analyzers and code-style enforcement on — 0 warnings, 0 errors.Uno.UI.RuntimeTests.Tests.Windows_UI_Compositionon Skia Desktop — 66/66 passing, including the 7Given_Visual_Damagetests.