Repository navigation
desktop: Pause frame clock during scroll indicator hold - #4057
Conversation
|
❌ Preserve existing ScrollHost implementations before accepting this scheduling optimization. At Scope/API review: stopping unchanged post-scroll frames is a useful bounded optimization, including scrolling inside an embedded GPUI surface. The public additions are Verification: reviewed the full diff and timer re-arm/failure/detach paths; Reviewed head: Independent root-session verification at 0325d43: |
0325d43 to
c1a5bb5
Compare
|
Addressed the source-compatibility feedback in
|
|
💡 The compatibility defect is fixed; the new public scroll API and a small scroll regression in the posted benchmark still need the owner's decision.
Recommendation: accept once the scroll gap is shown to be noise and Reviewed at c1a5bb5 |
|
Thanks for re-reviewing! Addressing the two remaining points:
|
c1a5bb5 to
31be181
Compare
|
💡 Earlier compat issue is fixed and the perf rerun shows no regression; the new public scroll API needs a maintainer call.
Reviewed at 31be181 (read-only diff review; CI still pending). |
31be181 to
0d5945e
Compare
|
Rebased onto latest |
huacnlee
left a comment
There was a problem hiding this comment.
✅ All earlier review points are addressed; the scheduling hooks are now kept out of the documented API.
- Compat:
ScrollHost::wake_afterhas a default returningfalse(crates/nsh-core/src/scroll.rs);crates/nsh-core/tests/scroll_compat.rscovers a v0.8.0-style host without it. - Public surface:
ScrollHost::wake_after,scroll::indicator_hold_leftandscroll::hold_endedare#[doc(hidden)];indicator_hold_leftstayspubonly becausensh-platform-macoscalls it (crates/nsh-platform-macos/src/scroll.rs:64). No addition to the documented 0.9 surface. - Perf: paired macOS
jank.py --runs 3shows scroll frame p95 2.42 ms on both main and head; the single 16.67 ms gap also appears on main. No Linux/Windows numbers, non-blocking since the change only removes idle frames after scrolling stops. - Logic: one timer per hold, re-armed by
hold_ended, frame-callback fallback when no timer can be armed; no path leaves the indicator stuck. - CI was queued at review time; merge only once green.
Reviewed head: 0d5945e
Description
Patch upstreamed from https://github.com/apache/maka (Apache-2.0).
On desktop backends (macOS, Linux, Windows, and embedded GPUI), showing the overlay scroll indicator keeps it at
alpha = 1.0forINDICATOR_HOLD(800 ms) before fading out overINDICATOR_FADE(250 ms). Previously, the scroll frame callback kept running on every display frame throughout the entire 800 ms hold period even though nothing changed on screen—so idle post-scroll holds and streaming content that periodically scrolls to the bottom kept the display link / frame clock running continuously.This change pauses the frame callback once only the indicator hold remains and arms a single one-shot timer for the remaining hold duration (measured from the current monotonic clock rather than the previous frame timestamp):
nsh-core: TracksLive::hold_timer, addsindicator_hold_left(since),hold_ended(host), andScrollHost::wake_after(&self, ms: u64) -> bool(default returnsfalsefor source compatibility with existingScrollHostimplementations). Whenwake_afterreturnsfalse(e.g., Win32SetTimerfailure),frame()clearshold_timerand stays on the existing frame-callback path instead of wedging future fades. If the indicator was shown again before the timer fires,hold_endedre-arms directly for the remaining hold without waking an empty frame; if detached or indicators were turned off, it avoids waking the frame clock.nsh-platform-macos: Mirrors the same hold-pause and re-arm behavior on macOS (Tick::Hold/wake_after_hold), keepingcosmetic_framebalanced and adding a#[cfg(feature = "dev")]AppView::display_link_running()hook with a native regression check (tests/native/scroll_indicator_hold.rs).nsh-platform-linux/nsh-platform-windows/crates/gpui/nsh-platform-gpui: ImplementsScrollHost::wake_afterusingglib::timeout_add_local_once,input::after_ms(now returningbool), andrt::after_ms(now returningbool). The GPUI change is withindocs/dev/gpui.md#scope("Input inside the surface: pointer, scrolling").Public API
nsh_core::scroll::ScrollHost: added#[doc(hidden)]provided methodfn wake_after(&self, ms: u64) -> bool(default returnsfalse) — scheduleshold_endedon the view's thread aftermsmilliseconds; returnsfalseif scheduling fails so core falls back to the frame callback path.nsh_core::scroll::indicator_hold_left(since: f64) -> Option<u64>(#[doc(hidden)]) — returns remaining indicator hold milliseconds, orNoneonce fading.nsh_core::scroll::hold_ended(host: &impl ScrollHost)(#[doc(hidden)]) — called when the hold timer fires to start fading or re-arm for remaining hold.nsh_platform_macos::AppView::display_link_running(&self) -> bool(#[cfg(feature = "dev")]) — test hook reporting whether the display link is currently unpaused.Breaking Changes
None.
ScrollHost::wake_afterdefaults to returningfalse, so existing externalScrollHostimplementations continue compiling and fall back to the frame callback path (covered bycrates/nsh-core/tests/scroll_compat.rs).How to Test
Verification Results
nsh-core scroll::: 42 passed (including hold pause, re-arm without extra frame start,wake_afterfailure fallback, detached/hidden indicator cleanup, and lagging frame timestamp).nsh-platform-macos --lib scroll::: 22 passed.NSH_SCROLL_INDICATOR_HOLD_CHECK_ONLY=1: fails onmain(display link pauses during indicator hold never happened), passes on HEAD (scroll_indicator_hold: display link paused during hold and faded indicator out).NSH_SCROLL_INDICATOR_CHECK_ONLY=1: passed.examples/bench/jank/jank.py(--target macos --runs 3 --seconds 4, debugnsh+nsh-macos-host):main96838c858):startup 619 ms;animation120 Hzframe p95 0.61 ms / max 0.87 ms,gap 8.33/8.33/8.34 ms,over 0%;scroll120 Hzframe p95 2.26 ms / max 2.72 ms,gap 8.33/8.34/8.34 ms,over 0%(OK: within budget).0325d4317):startup 617 ms;animation120 Hzframe p95 0.65 ms / max 0.84 ms,gap 8.33/8.33/8.35 ms,over 0%;scroll120 Hzframe p95 2.64 ms / max 3.06 ms,gap 8.33/8.33/16.67 ms,over 0%(OK: within budget).cargo clippy -p nsh-core -p nsh-platform-linux --all-targets -- -D warnings: 0 warnings.cargo test -p nsh-core --lib scroll::: 42 passed.cargo test -p nsh-platform-linux --lib scroll::: passed.cargo clippy -p nsh-platform-windows --all-targets -- -D warnings: 0 warnings.cargo test -p nsh-core --lib scroll::: 42 passed.cargo test -p nsh-platform-windows --lib scroll::: 3 passed.cargo check --manifest-path crates/gpui/Cargo.toml -p nsh-platform-gpui --features runtime-shaders: passed.Checklist
crates/gpui, it is one of the changes the GPUI backend's scope accepts, and the description says which.jank.pybefore/after and AppKit hold regression check), Linux, Windows, and GPUI.