Skip to content

Web: the first wheel after idle presents its result ~2 s late (once per idle), on both the CPU canvas and WebGL2 #2549

Backlog

Description

@ajianaz

What happens

On a full-window Rune web page that has gone idle, the first wheel event produces its visible frame ~2 s late — once. The pan/zoom itself is computed and drawn quickly (a screenshot taken 300 ms after the wheel already shows the moved content), but the frame that presents it arrives after a long hole in the frame log. Every wheel after the first is clean at vsync.

Frame gaps around the first wheel (app-instrumented on_frame_drawn deltas, headed Chromium on Apple M2, CPU canvas via RUNE_CPU_FIRST=only):

2.1, 8.3, 32.4,   <- pan applies here; a screenshot at +300 ms already shows it
2103.0,           <- the hole; nothing presents for ~2.1 s
61.8              <- one more frame, then the app goes idle again

The same one-time hole reproduces on the WebGL2 path, at any scene size (10 to 20,000 nodes; the scene content is irrelevant — it reproduces with a fixed cost of one canvas(Shape) and a handful of els), and after a drag has already warmed the GPU path.

What does not cause it

  • Tx::instant() after handling the wheel — no change.
  • The app's own handling: on_wheel consumes the event and only mutates two f32s. Moving the wheel handling into on_magnify (ctrl+wheel) behaves the same.
  • Fonts: pre-fetching the three Inter faces before init() does not change it.
  • A bare 2D-canvas control page (plain rAF loop + preventDefault wheel listener) driven with the identical Playwright dispatch shows a worst rAF gap of 21.5 ms — so the dispatch, the browser and the synthetic wheel are not the cause.
  • Scene size and renderer: identical timing at 100 and 20,000 nodes, on CPU-first and WebGL2.

Reproduce

A minimal harness (cdylib crate, one canvas(Shape) surface with on_wheel/ on_magnify/ on_drag, plus a composer text_input so the web text bridge is live):

git clone https://github.com/ajianaz/rune-web-spike   # branch: main, commit c3e264c
cd rune-web-spike
cargo build --target wasm32-unknown-unknown --lib --release
wasm-bindgen --target web --out-dir web --out-name app \
  target/wasm32-unknown-unknown/release/spike_canvas.wasm
# serve ./web statically (mime application/wasm), then in a browser:
#   click once on the canvas to give it focus, wait ~2 s, wheel once

Observed with Chromium 140 (Playwright build), --enable-unsafe-webgpu, headed, macOS 15 arm64 (Apple M2). The spike records every on_frame_drawn into window.__spikePerf.frames, so the gaps are visible from the page console.

Context

This matters for canvas-style apps (the frame after an idle user's first wheel is the one they see). Suspected neighbour: the deferred-present mechanics documented in #2470 (handover freeze and the WebGL2 completion poll on an 8 ms setTimeout), though this reproduces without a handover on a page that never leaves the CPU canvas.

Happy to test a fix or more diagnostics against the harness above.

Activity

  1. ajianaz commented on Nov 27, 2026

    @ajianaz
    Author

    Repro pushed: https://github.com/ajianaz/rune-web-spike (branch main, commit 9e14b01). The web/index.html shell and the three Inter faces are committed; the wasm is built from source per the instructions in the issue body.

  2. opencodejr commented on Nov 27, 2026

    @opencodejr
    Contributor

    looked through the web wheel and frame loop (platform/web.rs, platform/web/input.rs, platform/web/frame.rs, platform/web/bridge.js, and vendored winit's web backend) and didn't find any ~2 s delay or timer on that path: on both RUNE_CPU_FIRST=only and steady-state webgl2, MouseWheel schedules one requestAnimationFrame, and on_frame_drawn runs synchronously right after cpu.paint / queue.present in that same rAF callback (so if a screenshot at +300 ms already shows the pan, that frame's on_frame_drawn already ran before +300 ms). because rune is demand-driven and draws zero frames while idle, consecutive on_frame_drawn deltas also span the idle wait itself, unlike a continuous-rAF control page.

    ajianaz/rune-web-spike returned 404 (probably private). could you share:

    1. raw performance.now() timestamps for the wheel dispatch, on_wheel, and each on_frame_drawn around it, so we can see whether the ~2.1 s delta is t_frame - t_wheel, the ~2 s idle wait before the wheel, or an extra wake ~2.1 s after the pan frame?
    2. whether changing the idle wait from ~2 s to ~5 s moves the gap to ~5 s or keeps it around ~2 s?
    3. the minimal lib.rs and dispatch snippet if the delay really is after the wheel event?
  3. Hona commented on Nov 27, 2026

    @Hona
    Member

    ajianaz/rune-web-spike is accessible now, so I inspected the repro scripts alongside Rune's web wheel and frame loop (crates/rune/src/platform/web.rs, platform/web/input.rs, platform/web/frame.rs, platform/web/handover.rs, platform/web/bridge.js, input/host_events.rs, runtime/web/a11y/schedule.rs, and vendored winit's web backend).

    What is causing the ~2.1 s delta in the repro

    wheel-visual2.mjs (as well as first-wheel.mjs, visual-wheel.mjs, zoom-only.mjs, and warm-gpu.mjs) runs page.waitForTimeout(2000) (plus const s0 = await page.screenshot() in wheel-visual2.mjs) without clearing window.__spikePerf.frames, and then computes consecutive deltas fs[i].t - fs[i - 1].t across the entire array.

    Because Rune is demand-driven (ControlFlow::Wait, drawing zero frames while idle), the [2.1, 8.3, 32.4, 2103.0, 61.8] trace in wheel-visual2.mjs is:

    • 2.1, 8.3, 32.4 ms — boot frames drawn right after load (initial CPU frame, bridge.js init, resize/layout, and full_faces font arrival).
    • 2103.0 ms — the idle period itself (waitForTimeout(2000) + ~100 ms page.screenshot()) between the last boot frame and the first post-idle input frame (page.mouse.move(720, 450) hovering the .hit() surface).
    • 61.8 ms — the delta between that hover frame and the page.mouse.wheel(0, 240) pan frame.

    That accounts for every symptom reported:

    • Why the +300 ms screenshot (s1) already shows the pan and s1 -> s2 does not change: the pan frame already painted and fired on_frame_drawn immediately on the next requestAnimationFrame after mouse.wheel, and zero frames ran during the second 2 s wait.
    • Why it reproduces identically on RUNE_CPU_FIRST=only and WebGL2, at 100 or 20,000 nodes, and with Tx::instant(): on RUNE_CPU_FIRST=only, GpuStartup and Draw::HandingOver never run; the ~2 s delta is the idle wait before input.
    • Why the bare 2D-canvas control (browser-wheel.html) has a 21.5 ms max gap: it runs a continuous requestAnimationFrame(loop) throughout waitForTimeout(2000), so consecutive timestamps never span the idle wait.
    • Why phone-wheel.mjs saw no ~2 s hole: unlike wheel-visual2.mjs, phone-wheel.mjs clears window.__spikePerf.frames.length = 0 before mouse.wheel and measures tFrame - t0 directly.

    What was checked in Rune

    • On WindowEvent::MouseWheel, Running::window_input -> host_events::web_wheel queues Action::Wheel and returns true, which immediately calls window.request_redraw() -> window.requestAnimationFrame.
    • In that rAF callback (Browser::redraw -> host_step::run), Rune steps the runtime, paints (cpu.paint or queue.present), and calls on_frame_drawn (inspect_frame) synchronously before returning.
    • Neither the CpuOnly path nor steady-state Gpu has a ~2 s timer, rest delay, or deferred-present wait on wheel (web_a11y::schedule flushes off-rAF without requesting redraws, and page_fonts::share_later does not request redraws).

    (Note: this was verified by reading the repro scripts and Rune's web code; the spike harness was not executed locally in a browser.)

    If you clear window.__spikePerf.frames right before mouse.wheel and measure t_on_frame_drawn - t_wheel_dispatch (using raw performance.now() timestamps) and still see a ~2 s delay after the wheel event, please share those timestamps and we will dig back in — otherwise this looks like expected demand-driven idle behavior rather than a Rune bug.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions