Skip to content

perf(terminal): stop re-reading the fit grid on every foreground write once it matches - #35783

Merged
nwparker merged 3 commits into
mainfrom
perf/grid-drift-probe-35273
Oct 29, 2026
Merged

nwparker merged 3 commits into
mainfrom
perf/grid-drift-probe-35273

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​140 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​140
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​99 $\color{#cf222e}{\Huge{\mathbf{−}}}$​45 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​54

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

  • New pty-connection/foreground-grid-drift-probe.ts holds the probe, moved out of pty-input-forward.ts to stay under the line limit.
  • After a 'matched' probe, non-forced probes wait FOREGROUND_GRID_DRIFT_SETTLED_RECHECK_MS (1000 ms) instead of 250 ms.
  • Existing geometry signals restore the 250 ms cadence: xterm onResize, the pane ResizeObserver (pty-resize-geometry.ts), noteVisibilityResume and reassertPtySizeAfterWindowWake (session-reconcile-dispose.ts). No new size tracking is added.
  • A write that is skipped by the interval arms one trailing probe per session for when the interval ends. That way drift is still repaired when output stops mid-interval.
    • The timer is pulled forward if a geometry signal shortens the interval.
    • It is cleared when a probe runs and on dispose.
  • read-pane-size.ts: measureTerminalGridFitDrift() returns 'drifted' | 'matched' | 'unknown'. An unavailable measurement never settles the probe.
  • Forced probes, which run when a text selection ends, still bypass the gap.

Why

#35273 profiled getPropertyValue <= proposeDimensions <- readProposedTerminalGrid <- terminalGridDriftedFromFit at 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.ts contract), 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 moved terminalGridDriftedFromFit into read-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 the body: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:

    • the settled probe waits for a geometry signal
    • repair after the backstop while output keeps streaming
    • the trailing probe repairs drift when output stops inside the interval
    • a geometry signal pulls an armed trailing probe forward
    • an unavailable measurement keeps the fast cadence
  • Each new spec fails with its fix reverted.

  • pnpm check:changed --maxWorkers=2 passes.

  • 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

…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.
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7103cd7a-430a-44ee-99bf-6c4ac8588e77
Commits

Reviewing files that changed from the base of the PR and between 1bfba51 and de36622.

Files selected for processing: 7
  • src/renderer/src/components/terminal-pane/pty-connection-visibility-resume-size.spec.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-grid-drift-probe.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-budgets.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-forward.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-resize-geometry.ts
  • src/renderer/src/components/terminal-pane/pty-connection/read-pane-size.ts
  • src/renderer/src/components/terminal-pane/pty-connection/session-reconcile-dispose.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Walkthrough

The change adds three-state terminal grid-drift measurement and installs a foreground probe with throttled checks and a settled recheck interval. Resize, visibility-resume, and window-wake events reset the settled state. Disposal clears the trailing probe. Tests cover streaming output, trailing checks, visibility resume, and unavailable fit proposals. Repair expectations verify a claimed resize to the proposed 65×63 grid.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Minimal · up to de366

The change reduces repeated grid checks while retaining the investigated repair paths. No merge-blocking risk was found.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main performance change: avoiding repeated fit-grid reads after the terminal grid matches.
Description check Passed The description includes all required sections, links issue #35273, explains the user impact and implementation, documents testing, and provides the required N/A visual proof for a performance-only ch…
Linked Issues check Passed Issue #35273 requires fewer repeated foreground grid-fit layout reads while preserving repair of output-only grid drift. foreground-grid-drift-probe.ts settles after a matching probe, uses the 1000 …
Out of Scope Changes check Passed The production changes move the probe, add settled scheduling state, connect geometry signals, distinguish unknown measurements, and clear timers during disposal. The test changes exercise these behav…
Full details: Description check

Explanation

The description includes all required sections, links issue #35273, explains the user impact and implementation, documents testing, and provides the required N/A visual proof for a performance-only change.

Full details: Linked Issues check

Explanation

Issue #35273 requires fewer repeated foreground grid-fit layout reads while preserving repair of output-only grid drift. foreground-grid-drift-probe.ts settles after a matching probe, uses the 1000 ms backstop, and restores the fast cadence after geometry signals. Forced probes bypass the delay. An unknown measurement does not settle the probe. The existing output-only repair test and new tests cover settled deferral, backstop repair, trailing repair, signal pull-forward, and unavailable measurements. The implementation meets the issue's coding requirements.

Full details: Out of Scope Changes check

Explanation

The production changes move the probe, add settled scheduling state, connect geometry signals, distinguish unknown measurements, and clear timers during disposal. The test changes exercise these behaviors. Each change supports the performance or repair objective in issue #35273. No unrelated change is established.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 7 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Summary

The PR reduces repeated terminal size reads after the grid matches. The current fallback interval is 1 second.

  • Terminal grid checks slow down after the grid matches its fit.

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.
@nwparker
nwparker merged commit def7fad into main Oct 29, 2026
48 checks passed
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.

[Bug]: terminal grid-drift probe forces a style read on every foreground write (~1.4s renderer time while an agent streams)

1 participant