garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/notes/camera-drag-pacing.md

raw


topic: camera-drag-pacing triggers: [free_camera.rs, pointer_trail.rs, camera_pacing.rs, os_drag.swift, DragReplay, CursorMoved, "drag", "judder", "stutter", "camera movement", no_drag_replay, firefox_probe, cdp_probe] updated: 2026-10-21

A drag moves the camera as evenly as the pointer events arrive

Every camera mode moves the camera by the cursor's movement since the last frame, from that frame's CursorMoved events. CursorMoved has no time on it, so the camera can only be as even as the delivery: a frame the browser handed no pointer event does not move, and the next moves twice as far. That is judder at a steady frame rate, and no frame-rate figure shows it.

Chrome hides it, Firefox does not. Chrome delivers pointer moves aligned with animation frames, one per frame: over a steady scripted drag on mac-2 (2026-10-21) 1–3% of its frames got none. Firefox does not align them: 27% of frames got none and 7% two, measured both at the page (a pointermove counter per animation frame, firefox_probe --drag) and in the client.

What is measured, and how

The fix: replay the trail by the browser's timestamps (web)

platform::pointer_trail records every pointer event's position with its timeStamp (the browser's own creation time, on performance.now()'s clock), expanding getCoalescedEvents() so a merged event loses nothing. Earth mode's DragReplay (free_camera.rs) replays that path a short delay behind the present and moves the camera by the path between last frame's moment and this one's, so the camera moves exactly as evenly as the hand.

The delay is the whole trade. It is how stale the newest sample tends to be when a frame looks, plus half a sample gap, between 8 and 50 ms: it rises at once when samples come late and eases back slowly, and is measured only on frames that got samples (a hand held still sends none, and that is not lateness). A first version that sized it from the sample gap alone stalled whenever a sample came late, and its own test caught it (spread 0.24 against a limit of 0.1). The cost: the camera trails the pointer by that delay, and the last delay's worth of a drag is dropped at release.

a_steady_drag_delivered_unevenly_replays_evenly is the specification: a 125 Hz mouse at a constant speed, each sample reaching the page 0–25 ms late, frames at 60 Hz. The events as they arrived have a per-frame spread over 0.3; the replay's is under 0.1 at the hand's speed.

?no_drag_replay (CARTO_NO_DRAG_REPLAY) turns it off, to compare by hand. Natively there is no trail (winit's events carry no time) and the events are used as they come. Only Earth mode replays; Fly and Follow still read raw events.

Not fixed here

Firefox's frame intervals are uneven too while a drag streams new ground: p95 28–85 ms against Chrome's ~23 ms on the same node. That is the other half of what a person calls stutter, and it is wasm-performance.md's business.