Skip to content

feat(composition): Measure scroll smoothness in SamplesApp - #24711

Merged
MartinZikmund merged 16 commits into
masterfrom
dev/mazi/scroll-probe
Oct 10, 2026
Merged

MartinZikmund merged 16 commits into
masterfrom
dev/mazi/scroll-probe

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #24708

Related: #23985

PR Type:

✨ Feature

What changed? 🚀

Problem: scroll-smoothness fixes and regressions (frame pacing, judder, stalls) were validated by eye — there was no repeatable, scriptable way to measure "did this actually get smoother" across the platforms and render paths Uno ships on.

Root cause: no diagnostics hook exists between the compositor's swap-chain present and anything that wants to observe it, and the SamplesApp had no scenario that drives scroll input synthetically and scores the frames it produces.

The change:

  • Adds an internal CompositionTarget.FramePresented event, raised after swapChain.Present with the recorded frame's sequence number (a repeated sequence means the previous frame was shown again). Costs a null check when unsubscribed.
  • Adds a scroll-smoothness probe + synthetic input drivers to the ScrollSmoothnessTester sample, covering ScrollViewer and ScrollView tabs, with scenarios: wheel-burst, wheel-slow, touchpad, touch-fling, touch-drag, key-down, page-down, changeview, and external (records real OS/finger input).
  • Per-presented-frame metrics: fps vs newFps (distinct frames), frame-interval percentiles (motion-only), long frames, repeated/stalled frames, backward steps, judder (5-frame quadratic residual), maxStep and when it happened, record-to-present latency, first-input latency, host stalls.
  • Unattended runs: sample=Scrolling/ScrollSmoothnessTester&scrollprobe=all&scrolltabs=0,2,3,4,5 prints [scroll-probe] {json}.
  • Two small SamplesApp dev hooks used while collecting the evidence below: the UNO_SAMPLES_TRACE env var enables trace-logging categories, and (Android) adb shell setprop debug.uno.samples.renderer vulkan|gl|software picks the render view for the next launch.

Evidence:

  • Compile: dotnet build of SamplesApp.csproj -f net11.0-desktop -c Release against the .NET 11 preview SDK (UnoFastDevBuild=true) — 0 errors, 0 warnings.
  • Runtime: used to baseline and A/B every scroll-smoothness fix in this effort on Win32, WASM (desktop Chrome, Edge on Android), Android (Pixel Tablet 60 Hz, Galaxy Z Fold7 120 Hz; both Vulkan and GL), macOS and iOS (iPhone 13 Pro 120 Hz).

PR Checklist ✅

🤖 Generated with Claude Code

https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

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


Claude's review of #24711

  • Gather context (PR diff, description, AGENTS.md rules)
  • Review CompositionTarget.Rendering.cs / CompositionTarget.RenderScheduling.cs (FramePresented event)
  • Review ScrollSmoothnessProbe.cs
  • Review ScrollSmoothnessDrivers.cs
  • Review ScrollViewer_SmoothnessTester.xaml / .xaml.cs
  • Review App.xaml.cs, App.Tests.cs, Main.Android.cs
  • Post inline findings
  • Post summary

Verdict: fix-first

3 findings posted inline (1 medium, 1 medium/correctness, 1 low):

  • Medium — OnLoaded (ScrollViewer_SmoothnessTester.xaml.cs) is async void with no top-level try/catch guarding the pre-RunScenariosAsync work; a malformed scrolltabs launch arg (int.Parse) or an out-of-range Tabs.SelectedIndex throws unhandled on the dispatcher.
  • Medium/correctness — ScrollSmoothnessDrivers.PlayAsync's background timing thread doesn't honor CancellationToken for the work itself, only for the timing delay: once cancelled it fast-forwards through all remaining steps and still injects real synthetic input, which can leak into whatever runs next (including the next scenario's measurement window).
  • Low — _runCts is replaced without disposing the previous CancellationTokenSource in RunScenariosAsync.

Cross-cutting observations (no inline comment needed):

  • The new CompositionTarget.FramePresented event correctly uses EventHandler<TEventArgs> (not Action<T>), is well-documented as firing on the presenting thread (not necessarily the UI thread), and ScrollSmoothnessProbe correctly locks around _presents (mutated cross-thread) while leaving _records/_inputs unlocked (UI-thread-only, matching where FrameRendered fires) — this thread-safety split is correct and deliberate, not a bug.
  • RaiseFramePresented/_pendingPresent add negligible overhead when unsubscribed (single null check), matching the PR description.
  • XAML attribute formatting spot-checked by hand against Settings.XamlStyler (AttributesTolerance: 2) and looked consistent; I could not run dotnet xstyler in this sandbox (tool restore requires approval I don't have here) — worth a final CI check.
  • Manual/diagnostic scope: this is a IsManualTest = true sample plus an internal diagnostics hook, so the bar is lower than product code, but the cancellation-leak finding above can still cause confusing/misleading measurements between runs, which undercuts the tool's whole purpose (repeatable measurement).

@github-actions github-actions Bot added platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform area/automation Categorizes an issue or PR as relevant to project automation labels Sep 25, 2026
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

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


Claude's review of #24711

  • Gather context (PR diff, AGENTS.md rules)
  • Confirm HEAD (6db1e5d4) is unchanged since the prior review pass — no new commits landed
  • Independently re-review all 9 changed files for correctness/cancellation/style issues
  • Post new inline findings
  • Post summary

Verdict: fix-first

2 new findings posted inline (both medium, correctness):

  • ScrollViewer_SmoothnessTester.xaml.cs — RunScenariosAsync's finally block isn't guarded against an older, cancelled invocation's cleanup racing a newer one: buttons briefly re-enable between OnLoaded's sequential per-tab calls, so a manual click during that gap can start an overlapping run whose state later gets clobbered by the cancelled run's own finally.
  • ScrollSmoothnessProbe.cs — the judder-residual guard checks counted[i-1..i+2] but QuadraticResidual fits over 5 points (i-2..i+2); counted[i-2] is never checked, so an excluded/paused frame can enter the fit and skew judder values at pause/resume boundaries.

Status of the previous review pass (unchanged commit, so still open): the three issues from the earlier Claude review — OnLoaded's unguarded async void (malformed scrolltabs/out-of-range tab index throws unhandled), PlayAsync's background thread not actually stopping remaining input injection once cancelled, and the un-disposed _runCts on replacement — remain present in the code as-is. The github-code-quality finding (generic catch (Exception) in Main.Android.cs's GetSystemProperty, suggesting Java.Lang.Throwable) is likewise still open.

Cross-cutting observations (no inline comment needed):

  • The CompositionTarget.FramePresented diagnostics addition is clean: _pendingPresent/RaiseFramePresented are only touched from Draw/OnNativePlatformFrameRequested's own call stack (same presenting-thread invocation), so there's no cross-thread race despite the lack of explicit locking; cost when unsubscribed is a single null check as described.
  • Main.Android.cs's new debug.uno.samples.renderer system-property switch correctly maps to existing FeatureConfiguration.Rendering.UseVulkanOnSkiaAndroid/UseOpenGLOnSkiaAndroid flags; no nullable-annotation warning from GetSystemProperty returning null since this file isn't under #nullable enable.
  • Manual/diagnostic scope (IsManualTest = true sample + internal diagnostics hook) keeps the bar lower than product code, but both new findings affect the accuracy/reliability of the very measurements this tool exists to produce, so they're worth fixing before relying on the numbers.
  • Could not run dotnet xstyler or a build in this sandbox; XAML formatting was spot-checked by hand against Settings.XamlStyler and looked consistent.
    (branch: dev/mazi/scroll-probe)

Copilot AI balanced review requested due to automatic review settings October 2, 2026 05:55
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

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


Claude's review of #24711

  • Gather context (PR diff, AGENTS.md rules)
  • Confirm HEAD (e7fe1651) is a new commit since the last review pass — re-verify it against prior findings
  • Re-review all 9 changed files for new/unresolved issues
  • Post inline findings (none — see below)
  • Post summary

Verdict: ship

No new findings. HEAD (e7fe1651, "fix(samples): Harden scroll probe run and cancellation") verifiably addresses every issue raised across the two prior review passes:

Prior finding Fixed in e7fe1651
OnLoaded was async void with no top-level try/catch (malformed scrolltabs/out-of-range tab index could crash unattended runs) Now wraps the whole body in try/catch (Exception), flushes results and prints [scroll-probe] error … on failure
ScrollSmoothnessDrivers.PlayAsync's background thread didn't stop injecting remaining steps once cancelled RunDue now bails (and clears pending) when ct.IsCancellationRequested, and the per-step foreach returns immediately after the busy-wait loops if cancelled, instead of enqueueing every remaining step
_runCts replaced without disposing the previous CancellationTokenSource finally now disposes the captured cts unconditionally
RunScenariosAsync's finally could let an overlapping/superseded run clobber newer run state (_isRunning, button re-enable, FlushResults) finally now guards the reset with ReferenceEquals(_runCts, cts), so only the run that still owns the current token resets shared state
ScrollSmoothnessProbe's judder-residual guard checked only 4 of the 5 points (i-1..i+2) the quadratic fit uses (i-2..i+2), letting an excluded/paused frame skew judder near pause/resume boundaries Guard now includes counted[i - 2]
github-code-quality: generic catch (Exception) in Main.Android.cs's GetSystemProperty Narrowed to catch (Java.Lang.Throwable)

I independently re-read each of the four touched files in this commit (ScrollSmoothnessDrivers.cs, ScrollSmoothnessProbe.cs, ScrollViewer_SmoothnessTester.xaml.cs, Main.Android.cs) against the diff and confirmed each fix is a real root-cause correction, not a guard bolted on top: cancellation now actually stops the input-injection loop instead of just skipping its timing delay, and the run-ownership guard correctly scopes cleanup to the token that owns it (including disposal) rather than adding a defensive null-check.

Cross-cutting, no action needed:

  • The core CompositionTarget.FramePresented diagnostics hook (CompositionTarget.Rendering.cs / .RenderScheduling.cs) is unchanged since the last pass — RaiseFramePresented() runs synchronously right after swapChain.Present() in the same OnNativePlatformFrameRequested call frame as Draw, so _pendingPresent has no cross-thread race despite lacking a lock, and the cost when unsubscribed is a single null check as described in the PR body.
  • App.xaml.cs/App.Tests.cs's UNO_SAMPLES_TRACE and LaunchQuery additions are simple, synchronous, set once at startup — no concurrency concerns.
  • This remains manual/diagnostic scope (IsManualTest = true sample + internal dev hooks), already human-approved (@Xiaoy312).

Validation: Code-review only (static diff inspection) — I did not build or run this in the sandbox. The PR description's own evidence (Release build + multi-platform runtime baselining) stands as the runtime validation for this change.
(branch: dev/mazi/scroll-probe)

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.

Copilot review overview

🟡 Changes recommended

Cancellation and teardown defects can leak probes, continue unattended runs after unloading, leave injected touches active, and skew latency measurements.

Review effort: Balanced
Findings: 5 Medium severity

Open (5)
What changed in this PR

Adds quantitative scroll-smoothness diagnostics and synthetic scrolling scenarios to SamplesApp.

Changes:

  • Adds frame-presentation sequencing and timestamps.
  • Adds scrolling drivers, analysis metrics, JSON output, and UI.
  • Adds logging and Android renderer-selection hooks.

Review verdict: 5 bugs found, primarily around cancellation, cleanup, and metric accuracy.

File Description
CompositionTarget.RenderScheduling.cs Raises presentation notifications after swap-chain presentation.
CompositionTarget.Rendering.cs Tracks frame sequences and presentation metadata.
Main.Android.cs Adds renderer selection through an Android property.
App.xaml.cs Enables trace categories through an environment variable.
App.Tests.cs Exposes launch query options to samples.
ScrollViewer_SmoothnessTester.xaml.cs Runs scenarios and reports results.
ScrollViewer_SmoothnessTester.xaml Adds probe controls and ScrollView cases.
ScrollSmoothnessProbe.cs Calculates frame-pacing and motion metrics.
ScrollSmoothnessDrivers.cs Generates synthetic scrolling input.

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

@unodevops

Copy link
Copy Markdown
Contributor

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

Copilot AI balanced review requested due to automatic review settings October 2, 2026 13:16
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/scroll-probe branch from 0e2b092 to b1340b2 Compare October 7, 2026 09:13

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 24s —— View job


Claude's review of #24711

  • Review the two new commits since the last pass (bd756389, b1340b2e) against the open Copilot findings
  • Check for new issues

Verdict: ship

No new findings. Both open Copilot findings from the last round are resolved.

Copilot finding Fixed in Check
Percentile indexing overstated P95/P99 bd756389 Percentile now uses nearest-rank: ceil(p·N) − 1, clamped to [0, N−1]. P95 of 20 samples is the 19th value. P50 of an even count picks the lower middle, which is the standard nearest-rank result.
No automated coverage for FramePresented b1340b2e Given_CompositionTarget.When_Frames_Presented_Then_Sequences_Advance is [RunsOnUIThread] and under #if __SKIA__, matching the neighbouring tests. It subscribes and unsubscribes in a try/finally. It locks the list because the event fires on the presenting thread. It waits for a sequence newer than the one recorded before each change, then asserts that distinct sequences, sequence order and timestamps never go backwards.

I also checked that the WaitFor(condition, timeoutMS, message) call matches the helper's signature in TestServices.WindowHelper.cs.

Non-blocking notes:

  • The test asserts >= recordedBefore for the first presented frame, which allows a frame recorded just before subscribing. The comment says this, so it isn't flaky. It does not check that a repeated sequence is ever reported, because that depends on the host re-presenting. The test covers ordering, not the re-present path.
  • The FramePresented event itself is unchanged since the earlier passes.

Validation: code review only, by reading the diffs of the two new commits. I did not build or run the runtime test in this sandbox.
· branch dev/mazi/scroll-probe

@unoplatform unoplatform deleted a comment from nventive-devops Oct 7, 2026
@unoplatform unoplatform deleted a comment from unodevops Oct 7, 2026
@nventive-devops

Copy link
Copy Markdown
Contributor

The build 237840 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 1139

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • ClipboardTests.png-dark
    • DropDownButtonPage.png-dark
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • DisplayInformation.png-dark
    • DynamicFont.png-dark
    • DynamicFont.png
    • ImageBrushInList.png-dark
  • skia-windows-screenshots: 1139 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AutoBorderStretchwithrightmargin.png-dark
    • AutomationProperties_AutomationId.png-dark
    • BitmapIcon_Monochromatic.png-dark
    • BitmapIcon_Monochromatic.png
    • Border_Simple_No_Background_With_TextBox.png-dark
    • Border_Simple_No_Background_With_TextBox.png
    • ClipboardTests.png-dark
    • ComboBox_Popover.png-dark
    • ComboBox_Popover.png
    • ComboBox_ScrollViewer.png-dark
    • ComboBox_ScrollViewer.png
    • AnimatedBackVisualSourceSamplePage.png
    • Basics_Automated.png-dark
    • Accessibility_ScreenReader.png-dark
    • Basics_Automated.png
    • BindableDrawerLayout_ChangePane.png-dark
    • BindableDrawerLayout_ChangePane.png
    • BorderTopwithmargins.png-dark
    • BorderTopwithmargins.png

@mergify

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

MartinZikmund and others added 16 commits October 9, 2026 14:21
Adds an internal FramePresented event on CompositionTarget, raised after the
swapchain presented, carrying the recorded frame's sequence number. A repeated
sequence means the previous frame was shown again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
The ScrollSmoothnessTester gains a frame probe and synthetic input drivers
(wheel, touchpad, touch drag/fling, keyboard, ChangeView) for ScrollViewer
and ScrollView hosts. Each run reports frame pacing, repeated/stalled frames,
backward steps and motion judder, and can run unattended from
'sample=Scrolling/ScrollSmoothnessTester&scrollprobe=all'.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
Adds an 'external' scenario that records while input comes from outside the app (a person, adb, CDP touch),
a hostStalls count for >250 ms presentation gaps, an opt-in console trace (&scrolltrace=1), and holds the
results TextBox still during runs so it cannot disturb the frames being measured.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
'adb shell setprop debug.uno.samples.renderer vulkan|gl|software' selects the view for the next launch,
so the same APK can be measured on each render path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
Pauses over 250 ms between two moves (discrete key presses, slow wheel ticks) are idle input, not slow
frames, so they no longer count towards frame intervals, long frames or host stalls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
Guard OnLoaded against bad query values, stop injecting input once
cancelled, keep a superseded run from resetting shared state, dispose
the run CTS, include the fifth point in the judder guard, and catch
Java throwables only in GetSystemProperty.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01G7PsEU6gSpLZXrYuK8WWpt
Copilot AI balanced review requested due to automatic review settings October 9, 2026 12:26
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/scroll-probe branch from b1340b2 to 12ce743 Compare October 9, 2026 12:26

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 13s —— View job


Claude's review of #24711

Verdict: ship (no new findings)

This push is a rebase (the HEAD commit message says "Rebased 2026-10-09"). The commit list is the same 16 commits as the last pass, ending in 12ce7439, and nothing new was added. The earlier review rounds already covered all of those changes, including the percentile fix and the FramePresented runtime test. I posted no inline comments.

Validation: I only checked the commit history with git log and git show --stat. I did not re-read the diff, build, or run anything in this sandbox. The CI screenshot-comparison differences reported by the bot are not something I investigated. They look unrelated to a manual-test sample and an internal diagnostics event, but please confirm that when you validate the Screenshots Compare Test Run item in the PR checklist.
· branch dev/mazi/scroll-probe

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 238524 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 1160

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • ClipboardTests.png-dark
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • DynamicFont.png-dark
    • DynamicFont.png
    • DisplayInformation.png-dark
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Examples.png
    • ImageBrushInList.png-dark
  • skia-windows-screenshots: 1160 changed over 2474

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AppWindowFeatures.png-dark
    • Attributed_text_Simple.png
    • AutomationProperties_Relations.png
    • BitmapIcon_Monochromatic.png-dark
    • BitmapIcon_Monochromatic.png
    • BorderCenteredwithmargins.png-dark
    • BorderCenteredwithmargins.png
    • BorderLeftwithmargins.png-dark
    • BorderLeftwithmargins.png
    • BorderTopwithmargins.png-dark
    • BorderTopwithmargins.png
    • Border_AntiAlias.png-dark
    • Border_AntiAlias.png
    • Border_CornerRadius_Alignments.png-dark
    • Border_CornerRadius_Alignments.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClippingToControlBounds.png-dark
    • ClippingToControlBounds.png
    • CommandBar_With_Long_Sentences.png-dark

@MartinZikmund
MartinZikmund merged commit 13ebddb into master Oct 10, 2026
51 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/scroll-probe branch October 10, 2026 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Measure scroll smoothness in the SamplesApp

6 participants