Skip to content

Scroll frames pay O(realized visuals) Skia path booleans for damage #23984

Open

Description

@MartinZikmund

What would you like to be added? 💡

During a scroll, damage accumulation on Skia costs O(realized visuals) Skia path booleans per frame, and the result is degenerate.

Visual.ContributeDamageOnPaint early-outs only when !contentChanged && !moved && !shadowSilhouetteChanged. While scrolling, moved = matrix != _lastRenderMatrix is true for every visual in the scrolled subtree, so the early-out never fires. Each visual then pays, on the UI thread, inside Render():

  • OutsetForAntialiasing — SKPaint.GetFillPath (stroke-to-fill) plus Op(Union)
  • contentPath.Op(clipPath, SKPathOp.Intersect, contentPath)
  • damage.Union(regionPath) against a monotonically growing accumulator
  • damage.UnionRect(_lastRenderBounds) — a native CreateRectPath allocation plus another Op(Union)

For a ListView with ~200 realized visuals that is roughly 800 Skia path booleans per frame, each more expensive than the last as the accumulator grows.

The key observation: when everything in the subtree moved, the union is the scroll port's clip rect — an O(1) answer being computed in O(n) with the most expensive primitive available.

Why is this needed? 🤔

This is the single largest per-frame cost in Uno's scroll path on Skia. It is invisible on a desktop CPU and decisive on a phone, which is why scroll smoothness degrades sharply on Android/iOS and mobile-browser WebAssembly relative to Desktop.

Because the cost scales with the number of realized visuals, it penalises exactly the case users notice most: long, content-rich lists.

Renderer 🎨

  • Skia
  • Native

For which platforms 📱💻🖥️

All platforms 🌍 (Skia targets)

Anything else we need to know? 💬

Proposed invariant:

A frame whose only change is an ancestor transform contributes oldSubtreeRect ∪ newSubtreeRect, clamped to the scroll port clip, and skips the per-visual pathops entirely.

This is a self-contained rendering change with its own failure mode (missed repaints / visual artifacts), independent of scroll feel. It is being tracked separately from the frame-clock and scroll-physics work so it can be reviewed by rendering eyes on its own merits.

Activity

  1. self-assigned this
    on Aug 6, 2026
  2. added
    kind/enhancement
    triage/untriaged
    on Aug 6, 2026
  3. mikernet commented on Sep 7, 2026

    @mikernet
    Contributor

    Adding a data point from a real app, since this regressed noticeably for us moving from Uno.WinUI 6.5.237 to 6.7.103 (Uno.Sdk 6.5.36 → 6.7.22), Skia desktop head on Win32/OpenGL, .NET 10.

    Scenario: an ItemsRepeater + UniformGridLayout grid of ~2800 items inside a ScrollViewer, ~155 realized item visuals (each a Button with the default Fluent template containing a Grid, a FontIcon and a TextBlock). Test harness scrolls 60 steps of 40 px at ~16 ms intervals via ScrollViewer.ChangeView(disableAnimation: true) and measures process CPU time (Process.TotalProcessorTime) around the loop. Virtualization, realized counts and layout times are identical on both versions; the difference is entirely in rendering.

    Realized visuals Layout per step 60 scroll steps: wall / CPU
    6.5.237 155 12–86 ms 1560 ms / 688 ms
    6.7.103 155 15–128 ms 1918 ms / 3562 ms

    A sampled CPU trace (dotnet-trace, 25 s covering a longer scroll) on 6.7.103 shows where the extra time goes:

    • Visual.TryGetPaintDamageRegion → Visual.OutsetForAntialiasing (SKPaint.GetFillPath + SKPath.Op) and DamageRegionExtensions.Union/UnionRect: ~10.8 s inclusive on the UI thread, i.e. the per-visual path booleans described in this issue. ContributeDamageOnPaint never early-outs because every visual in the scrolled subtree has moved == true.
    • SkiaSharp.SKRoundRect.DisposeNative under SKNativeObject.Finalize: ~19 s on the finalizer thread. The Button templates' rounded clips hand out new native objects every frame (this is [Skia] Rounded clips rebuild a native SKPath on every frame #24221 / perf(composition): Cache the rounded-clip paths  #24230). Replacing the Button with a plain Border in the item template brings the 60-step CPU from ~3200 ms to ~1170 ms, and a bare item to ~610 ms, which is roughly the 6.5 figure for the full template.

    Neither TryGetPaintDamageRegion nor OutsetForAntialiasing exist in the 6.5.237 composition assembly, so this is new cost introduced with the damage-region tracking.

    Since #23986 was merged into feature/breakingchanges only, is a backport to master / a 6.7.x service release feasible? For a virtualized list this is the difference between smooth and visibly laggy wheel scrolling on 6.7 stable, and the workaround (avoid Button/rounded-clip visuals in item templates) is not something most apps can do.

  4. mikernet commented on Sep 12, 2026

    @mikernet
    Contributor

    Two clarifications to my comment above, plus new data.

    The workaround is not sufficient in practice. My earlier numbers can be read as "replace the Button and you're back to 6.5 levels", which isn't the case. The plain Border and bare-item rows were diagnostic strips, not shippable UI. What we actually shipped is a stripped-down Button template (rectangular Border root + ContentPresenter, hover/pressed via VSM, no CornerRadius, no ripple). On the same 60-step harness that measures ~1500 ms, against 688 ms for the full Fluent template on 6.5.237. So after applying the workaround we are still roughly 2.2x the 6.5 cost with visibly worse scrolling, and there is no further simplification left that keeps a usable control.

    Item template (60 scroll steps) CPU
    6.5.237, full Fluent Button 688 ms
    6.7.103, full Fluent Button 3562 ms
    6.7.103, our shipped lightweight Button ~1500 ms
    6.7.103, plain Border (diagnostic only) 1172 ms
    6.7.103, bare item (diagnostic only) 609 ms

    The cost is dominated by realized-but-offscreen visuals. Reducing ItemsRepeater.VerticalCacheLength from its default 2.0 to 0.5, which roughly halves the realized visual count and changes nothing else, is a clearly perceptible improvement in scroll smoothness. (That one is qualitative, on the WebAssembly head; the table above is the desktop harness.) The direction is worth noting: a smaller cache buffer increases realization and recycling churn, and it still feels smoother, which points at per-frame cost dominating realization cost. It also means much of the cost is paid by visuals sitting in the cache buffer, entirely outside the viewport clip, contributing nothing visible.

    That suggests a cheaper partial mitigation than #23986: could ContributeDamageOnPaint / TryGetPaintDamageRegion early-out for visuals whose bounds fall outside the current clip? Every visual in a scrolled subtree has moved == true, so as far as I can tell nothing culls them before the SKPaint.GetFillPath + SKPath.Op work. There may be a reason that's unsafe that I'm not seeing.

    Scope, and ruling things out:

    • Reproduces on the WebAssembly head as well, not just the Skia desktop head.
    • Not SkiaSharp related: moving from SkiaSharp 3.x to 4.152.0 made no measurable difference on WebAssembly and slightly improved desktop. The regression tracks the Uno version, and TryGetPaintDamageRegion / OutsetForAntialiasing don't exist in the 6.5.237 composition assembly at all.

    Finally, a triage request: this is currently labelled kind/enhancement. It's a measured regression between two stable releases (6.5.237 → 6.7.103) that affects any virtualized list, so it would be good to see it re-triaged as a regression. I assume that classification is also what determines whether #23986 can be backported to a 6.7.x service release.

  5. mikernet commented on Sep 19, 2026

    @mikernet
    Contributor

    Note: On WASM, this also appears to cause (or at least significantly contribute to) occasional sporadic crashes when scrolling - mono GC enters a collection while scrolling (which it does very often now) and sometimes something happens where it doesn't finish (my best guess right now is a JS stack overflow during GC that triggers while in a deep recursive measure/arrange), which then causes it to panic and exit the runtime on the next GC start.

  6. added
    kind/regression
    on Sep 20, 2026
  7. self-assigned this
    on Sep 21, 2026
  8. agneszitte commented on Sep 23, 2026

    @agneszitte
    Member

    Hi @mikernet, thanks again for the detailed data points, they were really helpful.

    To answer your question about backporting #23986, it's in progress.

    • The scroll-frame damage fix from #23986 has been backported (#24612) and is available now in Uno.Sdk 6.8.0-dev.49.
    • The 6.7 backport is open with #24582. Our internal measurements on it are similar to master, which already has the fix.
      While preparing to merge it into a 6.7 stable service release, we want to make sure it's properly fixed in your app as well.
      Could you try Uno.Sdk 6.8.0-dev.49 (Uno.WinUI 6.8.0-dev.183) with your 60-step harness, ideally with the full Fluent Button template, and share the numbers compared to your Uno.WinUI 6.5.237 / 6.7.103 results, please? Anything you notice on WASM while scrolling would be welcome too.

    We're doing internal testing on our side in parallel. Thanks a lot in advance for your help and feedback!

  9. mikernet commented on Sep 24, 2026

    @mikernet
    Contributor

    Thanks @agneszitte. I re-ran the same 60-step harness on Uno.Sdk 6.8.0-dev.49 (Uno.WinUI 6.8.0-dev.183), and re-measured 6.5.237 and 6.7.103 on the same machine and day so the numbers are directly comparable. Same setup as before: ItemsRepeater + UniformGridLayout, 2837 items, 155 realized tiles, default cache lengths, 60 steps of 40 px at ~16 ms via ScrollViewer.ChangeView(disableAnimation: true), Skia desktop head on Win32/OpenGL, .NET 10. CPU is Process.TotalProcessorTime across the loop (so it includes finalizer and GC threads), reported as the median of the runs with the min–max range.

    Uno.WinUI Item template Runs 60 steps CPU, median (min–max) Wall, median
    6.5.237 full Fluent Button 6 805 ms (266–1078) 1530 ms
    6.7.103 full Fluent Button 2 3602 ms (3484–3719) 2146 ms
    6.8.0-dev.183 full Fluent Button 6 1656 ms (672–2016) 1606 ms
    6.5.237 our lightweight Button 6 1242 ms (359–1797) 1562 ms
    6.7.103 our lightweight Button 2 1977 ms (1938–2016) 1540 ms
    6.8.0-dev.183 our lightweight Button 6 1867 ms (1266–2016) 1586 ms

    Takeaways:

    • The backport fixes the regression that mattered. With the full Fluent template, CPU drops from ~3.6 s on 6.7.103 to ~1.65 s on 6.8.0-dev.183, and wall time is back to the 6.5 level. On 6.7 the nominally ~1 s loop took 1.9–2.3 s, i.e. frames were stalling; on 6.8 it takes ~1.6 s, same as 6.5, so scrolling keeps up with input again.
    • It's not fully back to 6.5 levels. Fluent on 6.8 is still roughly 2× the 6.5 CPU. That is consistent with the second cost in my earlier trace, the per-frame SKRoundRect finalization from the Fluent Button template's rounded clips ([Skia] Rounded clips rebuild a native SKPath on every frame #24221 / perf(composition): Cache the rounded-clip paths  #24230), which this fix does not address.
    • The lightweight template shows no measurable change, and the run-to-run spread on this metric is about ±500 ms, so I would not read anything into those rows.

    WASM: subjectively a big improvement. On our real app (the same grid, Skia WebAssembly head, Chrome, using the lightweight button template), scrolling on 6.8.0-dev.183 feels at least twice as smooth as 6.7.x, with far fewer stutters. I don't have a CPU metric in the browser, so that one is qualitative.

  10. agneszitte commented on Oct 7, 2026

    @agneszitte
    Member

    Hi @mikernet, a new 6.8-dev Uno.Sdk with the remaining scrolling and rendering fixes is now available: Uno.Sdk 6.8.0-dev.60.

    Since 6.8.0-dev.49, it adds:

    • #24788: cheaper damage tracking while scrolling
    • #24786: less work on Win32 when elements move during layout
    • #24792: a running ProgressRing, AnimatedIcon or Lottie animation no longer repaints the whole window

    In our tests, scrolling is back to the 6.5 level or better.

    Could you try it with your harness and your app, on Win32 and WASM, and let us know how it goes? It would also help to know whether the WASM crash while scrolling still happens.

    Once you confirm, we'll bring the same fixes to the next 6.7 service release.

    Thanks again for your detailed reports!

  11. mikernet commented on Oct 7, 2026

    @mikernet
    Contributor

    @agneszitte Will give it a try, thanks!

    Regarding the crash - it has been extremely difficult to trace. I put all sorts of crash instrumentation into the app but I still can't pin down what is causing the runtime to exit exactly, and it also happens on AOT builds, albeit much less often, and with slightly varying conditions each time, so I am suspecting some kind of mono bug at this point, perhaps something to do with interpreted stack frame unrolling when an exception happens under some specific condition, or god knows what else it could be. I keep adding more and more instrumentation to try to get closer to the reason it is crashing, but no luck so far, lol...it's an elusive little bugger.

    If it is some kind of GC bug then hopefully the lower allocation rate now during paints will make it much less frequent either way :)

    Will report back!

  12. mikernet commented on Oct 8, 2026

    @mikernet
    Contributor

    Performance is 👌

    After some very long debugging and a lot of hair pulling, I finally figured out what was causing the crashes - filed issues for them, will submit PRs in a bit. Couple compounding "leaky memory" type issues were pushing the WASM app over the 2GB memory limit, unrelated to anything in this issue.

  13. mikernet commented on Oct 9, 2026

    @mikernet
    Contributor

    In case anyone wants the detailed results of my new perf runs:

    Uno.WinUI 6.5.237, 6.7.103 and 6.8.0-dev.212 compared on scroll smoothness, desktop and WebAssembly.

    Setup

    • App and template: IconPackBuilder's icon grid, an ItemsRepeater with a UniformGridLayout and 2837 items, using the full Fluent Button template.
    • Window: 1920x1000 device-independent pixels at 125% scale on 120 Hz displays, with about 388 tiles realized.
    • Scroll: a fixed 2400 px/s for 4800 px, about 2 seconds, driven by elapsed time so every version scrolls at the same speed.
    • Builds: Release. Uno.WinUI 6.8.0-dev.212 comes from Uno.Sdk 6.8.0-dev.60.
    • Runs: warm runs only, which are runs 2 to 4 of each launch.
    • Desktop: Win32 with OpenGL, FrameRate set to 120.
    • WebAssembly: Chrome with a 1920x1000 viewport. The scroll is driven by a fast timer, and browser frame times come from a requestAnimationFrame recorder.

    Desktop: frames actually displayed

    Uno.WinUI Displayed frames/s Median frame 95th pct frame Worst frame Frames over 25 ms GCs Allocated Finalized
    6.5.237 59–63 15.7–15.8 ms 17–31 ms 30–39 ms 3–9 2 gen0 38 MB ~12,300
    6.7.103 3–7 110–304 ms 310–550 ms 310–550 ms all 2–3 gen0, 0–1 gen1 41–61 MB 10,000–12,200
    6.8 dev.212 61–77 12.7–15.4 ms 17–23 ms 36–45 ms 2–3 2 gen0 35 MB 12,300–12,600

    In 6.5 and 6.7, every frame recorded is presented, since rendering and presenting happen on the UI thread. In 6.8 they're on separate threads: the UI thread records a Skia picture, and a dedicated render thread replays and presents it. 6.8's row counts actual presents, read from Uno's own frame rate counter on the render thread.

    6.5.237 desktop at a quarter of the window area

    Window Tiles realized Frames/s Median frame 95th pct frame Worst frame Frames over 25 ms Allocated GCs
    1920x1000 DIP ~388 59–63 15.7–15.8 ms 17–31 ms 30–39 ms 3–9 38 MB 2 gen0
    960x500 DIP ~101 63.8–64.4 15.6–15.7 ms 16.3–16.5 ms 17.2–17.4 ms 0 14 MB 0–1 gen0

    6.5 is capped at about 64 fps on desktop regardless of FrameRate or workload. Its render timer can't fire faster than the default 15.625 ms Windows timer resolution.

    6.8 dev.212 desktop: recorded vs presented

    Measure dev.212
    Frames recorded by the UI thread per second 87–118
    Frames presented per second 61–77
    Recorded frames that reached the screen ~60–70%

    6.8 removed 6.5's timer cap. At this window size, its render thread becomes the limit, and about a third of recorded frames are replaced before they can be presented.

    WebAssembly, interpreted. One page load per version. Finalizer counts aren't available in WASM.

    Uno.WinUI New frames/s Avg time per new frame Browser frame rate Median browser frame Missed refreshes per scroll Browser frames over 25 ms Worst browser frame GCs Allocated
    6.5.237 28–31 32–36 ms 51–55 fps 16.6–16.7 ms 140–150 28–34 42–92 ms 6–7 gen0, occasional gen1/gen2 27.5 MB
    6.7.103 ~3 300–320 ms 6–7 fps 8.5–33 ms* 347–397 nearly all 650–790 ms 9–13 gen0, occasional gen1/gen2 40–51 MB
    6.8 dev.212 18–25 40–56 ms 41–53 fps 8.4 ms** 144–170 30–35 42–67 ms 5 gen0 19.7 MB

    WebAssembly, AOT (RunAOTCompilation=true). Two page loads per version.

    Uno.WinUI New frames/s Avg time per new frame Browser frame rate Median browser frame Missed refreshes per scroll Browser frames over 25 ms Worst browser frame GCs Allocated
    6.5.237 57–86 12–18 ms 91–118 fps 8.3–8.4 ms 5–60 0–3 17–83 ms 6–7 gen0, occasional gen1/gen2 27.6 MB
    6.7.103 3–5 200–330 ms 8–9 fps 8.5–33 ms* 311–326 nearly all 460–590 ms 9–11 gen0, occasional gen1/gen2 40–47 MB
    6.8 dev.212 69–84 12–14.5 ms 110–115 fps 8.3 ms 11–21 0–1 17–75 ms 5–7 gen0, occasional gen1/gen2 24–28 MB

    "New frames/s" counts distinct scroll offsets that were laid out. In the browser, painting happens in the browser's own frame callback on the same thread, so displayed frames are at most the smaller of new frames and browser frames.

    * 6.7's median looks deceptively low. Between its 450 to 800 ms stalls, the browser runs a handful of idle frames at full speed.

    ** 6.8's interpreted browser frames alternate between an idle 8.4 ms frame and a 33 to 50 ms frame doing layout and render. The median lands on the idle frames.

    Takeaways

    • The allocation and finalizer regression from 6.7 is fixed. dev.212 allocates as much as 6.5 or less, finalizes about the same number of objects, and runs no more GCs. 6.7 allocated more and ran more collections, sometimes gen1 and gen2.
    • Desktop. dev.212 displays about the same frame rate as 6.5, slightly higher and smoother. 6.5 is held back by its ~64 fps timer cap. dev.212 is held back by its render thread, which presents only 61 to 77 of the 87 to 118 frames per second the UI thread records.
    • WebAssembly, interpreted. dev.212 renders about 20 to 35% fewer new frames than 6.5, despite allocating less and collecting less often. The extra cost is per-frame managed work, which the interpreter runs slowly.
    • WebAssembly, AOT. dev.212 matches 6.5 on new frames, and its browser frame pacing is steadier.
    • 6.7.103 is unusable at this window size and scroll speed on every target.
  14. added
    7.0
    on Oct 14, 2026
  15. removed
    7.0
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

kind/enhancementkind/regressiontriage/untriaged

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions