Skip to content

Remove repeated row copying from terminal redraw ingestion - #26118

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-terminal-redraw-spans
Oct 8, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-terminal-redraw-spans

Conversation

@nwparker

@nwparker nwparker commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​76 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​75
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​30 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​19

ELI5

Long terminal redraws no longer make Orca rebuild an entire row for every character before delivering output.

What Changed

The retained terminal preview previously overwrote rows one code unit at a time, repeatedly copying the remaining row. It now writes each contiguous text span together and flushes it before existing newline, carriage-return, backspace and ANSI handling. Completed rows and the final partial own their retained storage so short text cannot keep a discarded large chunk alive.

Why

The synchronous ingestion path blocked on long overwritten rows: the production helper measured 10.11 ms for 16 KiB and 121.79 ms for 64 KiB. Span writes reduced those to 0.0375 and 0.163 ms. A 30-row, 160-column redraw improved 0.0996 to 0.0168 ms. The deterministic suffix-copy count falls from 32,769 to four for a 16 KiB row. This removes repeated work without changing terminal output caps, scheduling or adding a redraw classifier.

Linked Issue

Internal performance audit of delayed terminal input; related existing invariant: #14770. These measurements establish a long-row bottleneck, not the cause of every ordinary Codex typing stall.

Visual Proof

N/A — retained text and cursor results are unchanged; renderer painting, PTY input and output transport are untouched.

Testing

  • Automated tests added/updated.
  • 34 focused tests across five files pass, including the existing terminal-performance.padded-fullscreen-redraw gate, exact ANSI/UTF-16 outputs, trailing-space rewrites, copy counts and retained-memory checks.
  • 1,347 runtime/read/pagination tests passed, with one existing skipped case.
  • Independent comparison with the frozen old implementation: 20,000 randomized cases plus 50 saturated-cap cases match every result field. Independent review also checked 12,000 stateful chunks.
  • Full typecheck passed; final tc:node, targeted lint/format and changed-code quality passed.
  • Counterbalanced tiny-key/backspace/control-rich measurements show negligible absolute overhead: the extreme 200 cursor-move/one-character frame adds about 1.3 microseconds. No delay, output cap or visual fidelity tradeoff is introduced.
  • macOS Node 24.20.0 measurements. No live typing, Electron terminal, SSH/WSL or Linux/Windows native journey claimed.

Review

Invariant: preview text, cursor state, transcript counts, truncation and pagination remain identical (terminal-performance.padded-fullscreen-redraw). Failure source: synchronous per-character row copying in terminal ingestion. Oracle: exact results against the old implementation, operation counts and retained heap. Diagnostic artifacts include the benchmark JSON and deterministic regression assertions.

The algorithm is shared host-side code for local, daemon, SSH and paired-runtime output. No host selection, filesystem, wire, lifecycle or folder/worktree identity changes. Native provider journeys remain outside this pure string-operation check; CI covers other operating systems.

Agent skill upstream boundary

  • Not applicable.

Checklist

  • This PR is small and focused.
  • Before/after behavior, mechanism and approach explained.
  • N/A visual proof with reason.
  • Self-reviewed for correctness, security and performance.
  • Cross-platform and SSH/remote impact considered.
  • Typecheck, focused and broader runtime tests, and changed-code quality pass; full build/lint/suite left to CI.

@coderabbitai

coderabbitai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7a84259e-cd48-41c5-be0b-f36ec4f24bbf
📥 Commits

Reviewing files that changed from the base of the PR and between 4077fb4 and 359b124.

📒 Files selected for processing (3)
  • src/main/runtime/terminal-tail-redraw-buffer.ts
  • src/main/runtime/terminal-tail-redraw-spans.test.ts
  • src/main/runtime/terminal-tail-row-retention.test.ts

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


📝 Walkthrough

Walkthrough

The terminal-tail redraw buffer now writes contiguous text spans and flushes pending text around control characters. It retains completed rows as owned strings and conditionally owns trimmed text during finalization. New tests cover redraw controls, Unicode code units, cursor behavior, slice-call counts, and heap retention.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 359b1

No merge-blocking issue is established for the terminal redraw change. Proceed with normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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. Analyzed 2 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: reducing repeated row copying during terminal redraw ingestion.
Description check ✅ Passed The description explains the change, motivation, implementation, testing, visual-proof status, and compatibility considerations. It also identifies the related issue and notes that broader checks rema…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · 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.

@nwparker
nwparker merged commit 0eee1ce into main Oct 8, 2026
30 checks passed
@nwparker
nwparker deleted the nwparker/perf-terminal-redraw-spans branch October 8, 2026 07:22
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