Skip to content

perf(composition): Backport scroll-frame damage cost to 6.8 - #24612

Merged
ramezgerges merged 2 commits into
servicing/6.8from
backport/6.8/scroll-damage-perf
Sep 23, 2026
Merged

ramezgerges merged 2 commits into
servicing/6.8from
backport/6.8/scroll-damage-perf

Conversation

@ramezgerges

Copy link
Copy Markdown
Contributor

GitHub Issue: #23984

PR Type:

🐞 Bugfix

What changed? 🚀

Backport of the scroll-frame damage work to servicing/6.8, cherry-picked from the same two commits as #24582. 6.8 is in the same pre-fix state as 6.7: no DamageRegion, no preferBounds hint, SkiaSharpVersion at 3.119.0.

A frame's damage region was accumulated as an SKPath, and every contribution went through SKPath.Op(SKPathOp.Union) — a full path boolean. With ~111 realized visuals, one ItemsRepeater scroll frame paid ~222 of them.

perf(composition): Make scroll-frame damage cheaper for moved visuals — a visual that only moved, with unchanged content, reports its bounds instead of building and transforming a content path. TryGetPaintDamageRegion takes a preferBounds hint and skips the analytic path when local bounds are available.

perf(composition): Accumulate frame damage as rectangles — introduces DamageRegion, which holds the frame's damage as a bounded list of rectangles and materialises an SKPath only once per frame, in SnapshotAndReset, when the renderer needs one. Unioning becomes rect arithmetic: a contribution grows the open rect when that costs no extra area, otherwise closes it and opens a new one, collapsing to overall bounds past a rect cap. SKPath? damage becomes DamageRegion? damage through Compositor, Visual, PaintingSession, Visual.Damage, SkiaRenderHelper and CompositionTarget.Rendering; DamageRegionExtensions.skia.cs is superseded and removed.

This mirrors what is already on master. No SkiaSharp bump is required — the only 4.x-only idiom in master's version was SKPathBuilder, replaced here by an SKPath with Winding fill plus a scratch path for the frame clamp. SKPath.Transform(SKMatrix, SKPath) and SKPaint.GetFillPath(SKPath, SKPath) both exist in 3.119.

Both commits cherry-picked onto servicing/6.8 without conflicts.

Measurements

ItemsRepeater + UniformGridLayout in a ScrollViewer, 2800 items, 60 scroll steps of 40px at 16 ms, realized=111.

The measuring machine was under variable load, so rather than quote two absolute numbers the runs were interleaved in pairs (control, then backport, four times) so drift affects both arms equally:

Pair servicing/6.8 as-is with this PR Δ
1 2484 ms 2203 ms −11%
2 2828 ms 2219 ms −22%
3 3797 ms 3172 ms −16%
4 3734 ms 2484 ms −33%
mean 3211 ms 2520 ms −22%

CPU time over the scroll, lower is better; the backport is faster in every pair. The absolute values drift upward across the session and should not be compared against the figures in #24582, which were taken on a quieter machine.

Validation

  • Compile — Uno.UI.Composition.Skia, Uno.UI.Skia and SamplesApp.Skia.Generic (net10.0) build clean on this branch.
  • Runtime — Given_Visual_Damage passes 2/2 on Skia Desktop (When_Ancestor_Clip_Grows_Then_Revealed_Region_Is_Damaged, When_Clip_Shape_Changes_Within_Same_Bounds_Then_It_Is_Damaged). The fixture was adapted to the new type using the same SnapshotDamage helper master uses.

PR Checklist ✅

🤖 Generated with Claude Code

ramezgerges and others added 2 commits September 23, 2026 10:36
Backport of the preferBounds guard from master.

ContributeDamageOnPaint only early-outs when nothing changed, and during a
scroll every visual in the scrolled subtree has moved, so the early-out never
fires. Each visual then paid the expensive branch of TryGetPaintDamageRegion on
the UI thread - a stroke-to-fill outset plus two path booleans - and the cost
scaled with the number of realized visuals, which is exactly the long
content-rich list users notice.

A visual that only moved is damaged at its old location too, and that one is
only ever a rect, so computing exact geometry for the new location buys nothing.
Take the bounds branch instead, but only when bounds can actually answer for the
visual: falling through to the clip would report a far larger region than the
exact path it replaced. TryGetLocalContentBounds is asked directly rather than
hand-rolling the condition, since its overrides disagree with the obvious guess
(ShapeVisual bounds itself by its shapes without setting PaintsWithinOwnSize).

Deliberately excludes the SkiaSharp 4 idioms and the DamageRegion type that
landed alongside this on master: 6.7 is on SkiaSharp 3, and neither is needed
for the fix.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The per-visual damage union ran SKPath.Op(Union) for every contribution,
which is a full path boolean. At ~111 realized visuals a scroll frame paid
~222 of them. DamageRegion keeps the region as a bounded list of rects and
only materialises an SKPath once per frame, when the renderer needs one.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions github-actions Bot added the area/skia ✏️ Categorizes an issue or PR as relevant to Skia label Sep 23, 2026
@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

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

@ramezgerges
ramezgerges merged commit deeac10 into servicing/6.8 Sep 23, 2026
43 of 44 checks passed
@ramezgerges
ramezgerges deleted the backport/6.8/scroll-damage-perf branch September 23, 2026 17:26
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.

4 participants