Skip to content

Pen-down paints its dot at once; pen-to-ink latency in the debug overlay (#287) - #293

Open
Joost-8 wants to merge 1 commit into
mainfrom
claude/issue-287-android-latency-4d39c7
Open

Joost-8 wants to merge 1 commit into
mainfrom
claude/issue-287-android-latency-4d39c7

Conversation

@Joost-8

@Joost-8 Joost-8 commented Nov 21, 2026

Copy link
Copy Markdown
Owner

For #287 (latency on a Galaxy Tab S8 Ultra, against the Handwriting plugin).

What changed

  • The pen-down paints its dot on the next frame. Before, nothing was drawn until the first move's frame, so a pen that rests a moment before it moves (starting a letter, an i-dot) showed nothing until then. It is skipped while the stroke still waits for its first pressure or tilt reading, because that reading rewrites the start: a dot drawn before it could change once drawn, which the ink rule forbids.
  • A latency line in the Input debug overlay, to compare builds and settings on a device:
    lat ink 6/9ms frame 16/20ms in 242Hz 1.7n/ev desync=off
    • ink: median / 95th percentile, from the newest pen sample (its event timestamp) to the end of the wet paint that shows it.
    • frame: the same, to the start of the next frame, which is about when the paint reaches the glass. The compositor and the panel add more that no page can see.
    • in: samples a second from the pen, and samples per event.
    • desync: on (granted), asked (asked for and silently refused), off (setting off).

Measured

Perf harness (headless Chrome, GPU on, CPU 4x, real pen input through CDP at 240 Hz, 12 strokes a run):

  • Every wet paint lands in the same frame its move was dispatched in (about 1,000 paints, all of them). Chromium aligns pointermove with the frame, and our rAF runs inside that frame. So drawing in the handler, or from pointerrawupdate as the Handwriting plugin does, cannot reach an earlier frame without a front buffer.
  • Sample → paint: p50 3–5 ms, p95 6–9 ms. Sample → next frame: ~10 ms, the same order as the Handwriting plugin's own 7 ms. Our JS per writing frame is ~0.25 ms at full speed.
  • Pen-down → first ink, with the pen resting 20 ms before it moves: 30–32 ms → 9–12 ms; to the next frame, 37 → 15 ms. When the pen moves at once, nothing changes.
  • desynchronized on vs off: no difference in headless Chrome. It is granted there, but there is no real display to show the effect.

iPad over the bridge (iPad Air 5, 60 Hz; synthetic pen events on the installed 2.10.0 with the change patched in at runtime; a throwaway notebook, trashed afterwards):

  • With the pen resting ~30 ms, pen-down → first frame: 35–41 ms → 17–31 ms. Mid-stroke latency unchanged (sample → paint p50 6 ms, → next frame p50 22 ms).
  • WebKit grants desynchronized on the wet canvas.

Unproven on Android

  • Nothing here ran on an Android device or in Android WebView.
  • desynchronized: ours is on by default (the "Desynchronized canvas" setting). The Handwriting plugin turned it off after measuring it on Chromium (a 120 Hz Surface): with it on, moves came at 25–40 Hz instead of ~115, and ink was 25–37 ms old at present instead of ~7. According to Chromium's blink-dev thread, outside ChromeOS the hint only decouples input from the compositor frame; it does not give a front buffer. It may be costing us the same on Android. Not changed here; that is what to A/B.
  • Not taken over: the Handwriting plugin's predicted tail (≤12 ms / 10 px ahead of the pen, tapered, erased every event). It is probably part of why it feels faster, but it draws ink that later changes, which our ink rule forbids.

How to test (Android)

  1. Settings → FineNotes → turn on Input debug overlay.
  2. In a notebook, write a few lines of normal handwriting, then read the lat … line at the bottom of the overlay (a screenshot is enough).
  3. Turn Desynchronized canvas off, reopen the notebook, write the same lines, and read the lat line again. Note which one feels faster.
  4. Compare with 2.10.0 (or main) the same way: the ink and frame figures should match mid-stroke; the stroke start should feel quicker on this branch.

Gates: lint, lint:review, lint:css, typecheck, test, build all green locally.

🤖 Generated with Claude Code

…287)

Measured in the perf harness (headless Chrome, GPU, CPU 4x, real pen input
through CDP at 240 Hz): every wet paint already lands in the frame its move
was dispatched in, sample to paint 3-5 ms, to the next frame about 10 ms.
Drawing in the handler or from pointerrawupdate cannot reach an earlier
frame. What waited was the stroke start: the pen-down painted nothing until
the first move, so a pen resting 20 ms showed its first ink ~30 ms after
landing. It now schedules the wet paint (30 -> 10 ms there; on the iPad
over the bridge, first frame 35-41 -> 17-31 ms), except while a first
pressure or tilt reading could still rewrite the start, so the dot never
changes once drawn.

The diagnostics HUD gets a line for comparing builds on a device:
`lat ink 6/9ms frame 16/20ms in 242Hz 1.7n/ev desync=off` (median/p95 of
sample to wet paint and to the next frame, the pen's sample rate and
samples per event, and whether the low-latency canvas was granted).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant