Skip to content

perf(terminal): cap write-flush rate at ~30 fps - #64

Merged
JeanBaptisteRenard merged 1 commit into
mainfrom
perf/terminal-flush-30fps
Jun 12, 2026
Merged

perf(terminal): cap write-flush rate at ~30 fps#64
JeanBaptisteRenard merged 1 commit into
mainfrom
perf/terminal-flush-30fps

Conversation

@JeanBaptisteRenard

Copy link
Copy Markdown
Collaborator

Measurement (2026-06-12, live instance)

While one Claude session streams, the renderer's Compositor thread burns 40-60% of a core — terminal data is batched per-rAF, so every frame with pending output triggers parse + paint at 60 fps.

Change

33 ms minimum interval between flushes (MIN_FLUSH_INTERVAL_MS), tracked per session in lastFlushAt. When data arrives too soon after a flush, a timer covers the remaining interval before the rAF. The timer reuses buf.timerId so the existing teardown (flushTerminalBuffer, destroySession — #55) cancels it with zero new fields; lastFlushAt is cleaned in destroySession.

Trade-off

Worst-case +33 ms display latency on streaming text — imperceptible. Keystroke echo is unaffected when idle (first write after ≥33 ms quiet flushes on the next frame as before).

Verification

task check green — 214/214 (4 new tests: throttle window respected, burst coalescing, lastFlushAt cleanup, no late write after destroy). Expected effect: compositor ~50% → ~25% during streams.

(Implementation by implementer agent, interrupted by rate-limit mid-run; completed and verified by orchestrator.)

…nt cost

Measured 2026-06-12: while a Claude session streams, the renderer's
Compositor thread burns 40-60% of a core flushing terminal writes on
every animation frame. A 33 ms minimum interval between flushes halves
paint work and doubles parse-batch size; worst-case added display
latency is one frame (~33 ms), imperceptible for streaming text.

The throttle timer reuses buf.timerId so the existing teardown paths
(flushTerminalBuffer, destroySession) cancel it unchanged; lastFlushAt
is cleaned up in destroySession alongside the write buffer.
@JeanBaptisteRenard
JeanBaptisteRenard merged commit 87fa51a into main Jun 12, 2026
6 checks passed
@JeanBaptisteRenard
JeanBaptisteRenard deleted the perf/terminal-flush-30fps branch June 12, 2026 17:24
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