Skip to content

perf(wasm): Defer scrollbar thumb scrolling - #23581

Open
KRRT7 wants to merge 3 commits into
unoplatform:masterfrom
KRRT7:perf/wasm-scrollbar-thumb-drag
Open

KRRT7 wants to merge 3 commits into
unoplatform:masterfrom
KRRT7:perf/wasm-scrollbar-thumb-drag

Conversation

@KRRT7

@KRRT7 KRRT7 commented Jun 27, 2026 •

Copy link
Copy Markdown

GitHub Issue: closes #22495

PR Type:

🐞 Bugfix

What changed? 🚀

Defers browser-hosted ScrollViewer scrollbar ThumbTrack content scrolling so expensive virtualized layout work no longer runs synchronously inside the pointer move handler during thumb dragging.

This keeps the scrollbar thumb drag path responsive on Wasm Skia while preserving final offset application through the dispatcher. A WASM runtime regression test covers the deferred scrollbar thumb-track path.

Validation performed locally:

  • git diff --check
  • dotnet build src/Uno.UI/Uno.UI.Skia.csproj --no-restore -p:UnoTargetFrameworkOverride=net10.0 -p:UnoFastDevBuild=true
  • dotnet build src/Uno.UI/Uno.UI.Wasm.csproj --no-restore -p:UnoTargetFrameworkOverride=net10.0 -p:UnoFastDevBuild=true
  • dotnet build src/Uno.UI.RuntimeTests/Uno.UI.RuntimeTests.Skia.csproj --no-restore -p:UnoTargetFrameworkOverride=net10.0 -p:UnoFastDevBuild=true

Note: Uno.UI.RuntimeTests.Wasm.csproj restore succeeds, but its build currently fails in existing unrelated WasmSemanticDomHelper.cs usage of UIElement.Visual.

PR Checklist ✅

Copilot AI review requested due to automatic review settings June 27, 2026 04:52
@CLAassistant

CLAassistant commented Jun 27, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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 improves WebAssembly scrollbar thumb-drag responsiveness by deferring ScrollViewer content scrolling during ThumbTrack so expensive layout work doesn’t run synchronously in the pointer-move path, and adds a Wasm-only runtime test to validate the deferred behavior.

Changes:

  • Defer scrollbar ThumbTrack scroll offset application to the dispatcher on browser-hosted targets (Wasm).
  • Flush queued thumb-track offsets via a dispatcher callback.
  • Add a Wasm runtime regression test asserting thumb-track scrolling is deferred (not applied synchronously).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Uno.UI/UI/Xaml/Controls/ScrollViewer/ScrollViewer.cs Adds dispatcher-queued deferral for scrollbar thumb tracking and flush logic.
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Repeater/Given_ItemsRepeater_FastScroll.cs Adds a Wasm-only runtime test for deferred thumb-track scrolling behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or it will be closed in 10 days.

@github-actions github-actions Bot added the stale This item has been marked as stale and will be closed if there is no activity. label Aug 27, 2026
@MartinZikmund

Copy link
Copy Markdown
Member

/azp run

@MartinZikmund MartinZikmund removed the stale This item has been marked as stale and will be closed if there is no activity. label Aug 27, 2026
@azure-pipelines

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

@unodevops

Copy link
Copy Markdown
Contributor

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

The browser-only deferral preserves the latest request per axis, coalesces pending work, flushes it at EndScroll, and leaves desktop behavior unchanged. ScrollBar's completion path actually raises EndScroll, so the terminal flush is connected rather than theoretical. This intentionally changes browser event timing, not the final public scroll target; it should not be described as identical synchronous WinUI dispatch. Additional rapid-track and EndScroll cases would strengthen the existing deferred-offset case but are non-blocking.

@mergify

mergify Bot commented Sep 9, 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.

mikernet added a commit to Singulink/uno that referenced this pull request Oct 20, 2026
Port of unoplatform#23581 (f373381 and ceba7d8), for
unoplatform#22495.

In the browser, a scrollbar thumb drag scrolled the content
synchronously inside each pointer move, so a long virtualized list laid
itself out on every move: the content lagged behind the thumb and
jumped. Thumb track offsets are now kept and applied once per
dispatcher pass, and the last one is applied when the drag ends. Only
browser-hosted ScrollViewers and thumb dragging are affected.

- Test: Given_ItemsRepeater_FastScroll (WebAssembly).
KRRT7 and others added 3 commits November 10, 2026 15:07
Defer browser-hosted scrollbar ThumbTrack content scrolling so virtualized layout work does not block pointermove dispatch during thumb drag.\n\nAdds WASM runtime coverage for the deferred ScrollViewer path.\n\nFixes unoplatform#22495.
@MartinZikmund
MartinZikmund force-pushed the perf/wasm-scrollbar-thumb-drag branch from ceba7d8 to b9493d5 Compare November 10, 2026 14:09
@mergify

mergify Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

1 similar comment
@mergify

mergify Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

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

@KRRT7 thanks for digging into this one, the scrollbar drag on WASM is a real pain point (issue #22495). I'd like to take it in a different direction though, because I don't think the deferral fixes the root cause, and it moves us away from WinUI. Here's my reasoning:

  1. No measured gain. The PR doesn't include any numbers, and the work isn't removed, just moved. WASM is single-threaded, so the same ChangeViewCore → OnPresenterScrolled → ViewChanged cost still runs on the main thread, one setImmediate hop later, before the next frame. The only real saving is coalescing when several pointermoves land between dispatcher drains, and Chrome already rAF-aligns pointermove. Could you share a before/after trace (frame times, or Chrome perf profile) on the repro from the issue?
  2. Why the wheel is smooth and the thumb isn't. The wheel and touch go through ScrollContentPresenter.Set(..., IsIntermediate: true). For intermediate updates, ScrollViewer.OnPresenterScrolled coalesces VerticalOffset/ViewChanged via RequestUpdate() (the AsynchronousIdle updates mode) and skips InvalidateArrange. The thumb path calls ChangeViewCore, which is non-intermediate, so every move raises a final ViewChanged. For a ListView that runs VirtualizingPanelLayout.OnScrollChanged synchronously, and its UpdateLayout/materialization loop is the expensive bit in the issue's repro.
  3. WinUI semantics. dxaml/xcp/dxaml/lib/ScrollViewer_Partial.cpp: ScrollViewer::HandleVerticalScroll applies ThumbTrack synchronously (spScrollInfo->SetVerticalOffset(newOffset)), but first calls EnterIntermediateViewChangedMode(). EndScroll then calls LeaveIntermediateViewChangedMode(TRUE /*raiseFinalViewChanged*/). The only deferral WinUI does during a thumb drag is opt-in, through IsDeferredScrollingEnabled (m_verticalOffsetCached + SynchronizeScrollOffsetsAfterThumbDeferring on DragCompleted). This PR instead forces deferral on browser only, and still reports every flushed step as a non-intermediate ViewChanged.

The suggested direction: keep ThumbTrack synchronous, but route it as intermediate (plumb isIntermediate: true through ChangeViewCore/ChangeViewNative to ScrollContentPresenter.Set). On EndScroll, raise the final non-intermediate ViewChanged (note that Set won't call Updated if the offset didn't change, so EndScroll needs to force it). That reuses the coalescing that already makes the wheel smooth, and it works the same on every Skia target, not only the browser. It also keeps the content visual (AnchorPoint) moving in the same handler as the thumb, so there's no question of the thumb and content rendering on different frames. With the current deferral, the thumb's layout tick is queued before the flush, so a render can slip in between them.

Smaller points are inline. Happy to help if anything's unclear!

// internal so runtime tests can drive the scrollbar-drag path directly.
internal void OnVerticalScrollBarScrolled(object sender, ScrollEventArgs e)
{
if (e.ScrollEventType == ScrollEventType.ThumbTrack && TryDeferScrollbarThumbTrack(isVertical: true, e.NewValue))

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.

See the summary: WinUI applies ThumbTrack synchronously here, inside intermediate-ViewChanged mode (ScrollViewer::HandleVerticalScroll → EnterIntermediateViewChangedMode). I'd rather mark this as an intermediate update than defer it to the dispatcher.

shouldSnap: true);
}

#if __WASM__ || __SKIA__

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.

Uno.UI only builds for Skia now, so __WASM__ is never defined here, and the #else stubs are dead code. If this code stays, the #if can go.


if (verticalOffset is { } vertical)
{
_verticalOffsetIntent = vertical;

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.

The synchronous path arms the intent with ValidateVerticalOffsetIntent(offset) (same for horizontal). The flush stores the raw value, so if the extent shrinks between queue and flush, the intent ends up past the range and keeps chasing it as the extent grows. This is the case the ValidateOffsetIntent comment warns about.

NewValue = target,
});

sut.Scroller.VerticalOffset.Should().BeApproximately(initialOffset, OffsetTolerance,

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.

This asserts the implementation detail (the offset is not applied synchronously), and that is the opposite of WinUI, where the offset is applied synchronously during ThumbTrack. It also uses ItemsRepeater, which reacts to the effective viewport during layout, not to ViewChanged, so it doesn't cover the ListView path from the issue. With the intermediate approach, a better test would check that ViewChanged reports IsIntermediate == true during ThumbTrack, that a final IsIntermediate == false arrives on EndScroll, and that the offset ends at the target.

@mergify

mergify Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Wasm] [Release] Using scroll bar in long ListViews exhibits performance issues on Windows

6 participants