Repository navigation
perf(terminal): stop re-reading the fit grid on every foreground write once it matches - #35783
Conversation
…e once it matches (#35273) After a grid-drift probe finds xterm matching the fit, foreground output waits for a geometry signal (pane ResizeObserver, xterm resize, visibility resume, window wake) or a 2s backstop before forcing another proposeDimensions() read. The first probe after connect and after any signal still runs at the 250ms cadence, so drift without a pane resize is still repaired on output.
|
No actionable comments were generated in the recent review.
|
[Medium impact] The PR appears safe to merge; no new actionable issues were found. SummaryThe PR reduces repeated terminal size reads after the grid matches. The current fallback interval is 1 second.
Reviews (3) · Last reviewed commit: "fix(terminal): pull an armed grid-drift ..." · Reviewed by Greptile |
…1s backstop (#35273) - A foreground write skipped by the probe interval arms one trailing probe (per session, cleared on probe and dispose) so drift can't stick when output stops right after a throttled write. - measureTerminalGridFitDrift() returns 'drifted' | 'matched' | 'unknown'; only a valid matching proposal settles the probe. - Settled backstop shortened from 2s to 1s. - Probe moved to foreground-grid-drift-probe.ts (pty-input-forward max-lines). - Specs use fake timers and cover backstop, trailing probe, and unknown fit.
…he cadence speeds up
ELI5
While an agent streams output, Orca checked about 4 times a second whether the terminal grid had drifted from its pane size. Each check forces the browser to recompute styles. Once a check finds the grid matches, Orca now waits for a sign that the size could have changed, or 1 s at most, before checking again.
What Changed
pty-connection/foreground-grid-drift-probe.tsholds the probe, moved out ofpty-input-forward.tsto stay under the line limit.'matched'probe, non-forced probes waitFOREGROUND_GRID_DRIFT_SETTLED_RECHECK_MS(1000 ms) instead of 250 ms.onResize, the pane ResizeObserver (pty-resize-geometry.ts),noteVisibilityResumeandreassertPtySizeAfterWindowWake(session-reconcile-dispose.ts). No new size tracking is added.read-pane-size.ts:measureTerminalGridFitDrift()returns'drifted' | 'matched' | 'unknown'. An unavailable measurement never settles the probe.Why
#35273 profiled
getPropertyValue <= proposeDimensions <- readProposedTerminalGrid <- terminalGridDriftedFromFitat about 1.4 s of a 20 s renderer window while OpenCode streamed. That is about 7% of the main thread, and the largest single cost once the forced repaint is bounded (#35251). With this change, a streaming pane whose size doesn't change does about 1 layout read a second instead of about 4.The probe still has to repair drift on output even without a resize (the
pty-connection-visibility-resume-size.spec.tscontract), so it can't just be skipped while streaming. The issue's "probe once, then wait for a signal" idea is used here, with a 1 s fallback and a trailing probe kept for drift that no signal reports.Where this came from
This isn't a regression from a specific release. The 250 ms per-write probe (
FOREGROUND_GRID_DRIFT_CHECK_MIN_MS) predates the current history root (9bdb820). #33315 (219ad61, v1.4.241) only movedterminalGridDriftedFromFitintoread-pane-size.ts. In the 1.4.243 profile the probe was partly hidden behind the per-frame forced repaint (271 ms unpatched, versus about 1.4 s with #35251 applied). That's why it shows up now, alongside the #35660 and #35439 renderer-stall reports. Those two reports' main cause was thebody:has()rule from #33799, fixed by #34932.Linked Issue
Fixes #35273
Visual Proof
N/A: performance-only change with no visual or interaction difference.
Testing
pty-connection-visibility-and-exit.test.ts: 95/95 pass, including "repairs stale xterm grid drift on foreground output even without a pane resize". The probe specs use fake timers.New specs:
Each new spec fails with its fix reverted.
pnpm check:changed --maxWorkers=2passes.Adversarially reviewed by Opus and Codex (gpt-6.1-sol, xhigh). Their findings are fixed in follow-up commits on this branch.
Platform: tests ran on macOS. The change is renderer-only scheduling logic with no platform-specific branches, and remote panes use the same path.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Risk
Drift that no resize, reveal or wake signal reports, such as a font or DPI change that alters cell size without a resize, is now repaired within about 1 s instead of 250 ms.
🤖 Generated with Claude Code