Skip to content

perf(terminal): skip ordinary output in preview control scans - #19400

Merged
nwparker merged 2 commits into
mainfrom
nwparker/perf-terminal-vertical-control-scan-20260907
Sep 9, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/perf-terminal-vertical-control-scan-20260907

Conversation

@nwparker

@nwparker nwparker commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​85 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​85
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​72 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​65

ELI5

To decide how to draw a terminal's preview, Orca had to look at every single character of output just to find the rare "move the cursor up" marker. Now it jumps straight to those markers and skips the ordinary text in between, so the same preview is produced using noticeably less CPU on busy terminals. Nothing about what you see changes — only how much work the app does to figure it out.

Main terminal preview/read-tail updates scanned every ordinary output code unit to detect cursor-up controls. Use forward native ESC searches for the outer scan and retain the existing control parser, complete-payload skipping, incomplete-control stop and canonical CSI A recognition.

The production normalization → tail append → transcript → preview pipeline uses 13–22% less CPU across 4 MiB log fixtures: plain logs 43.418 → 37.932 ms, colored logs 49.321 → 42.570 ms, and no-newline output 32.009 → 25.100 ms. Ten thousand one-character writes into a growing partial line improve 190.374 → 126.820 ms. Rotated equal-bundle tiny-echo and redraw controls found no material regression; these are processing measurements, not end-to-end typing latency.

Validation: 22 new tests bound ordinary-text code-unit inspections (90k–98k → 0–5) and cover numeric/private/malformed CSI, embedded controls, incomplete payloads and exact redraw rows. Baseline comparison matched 204,925 predicates and 3,000 complete tail transitions. The exact original-base normalizer with only this change passed 1,298 tests with one existing skip across five suites; the integrated version passed 1,308 with that same skip. Full typecheck, changed-code quality and reliability-manifest validation passed.

Experimental gate: terminal-performance.vertical-control-scan, with a deterministic work/fidelity oracle and recorded performance budget. No new state, timers, IO, backpressure, published content or remote protocol changes. Folder workspaces and all hosts use the same string semantics. Live Electron/native input, SSH/WSL/Linux/Windows and many-pane frame measurements remain gaps. The PR starts from the original base and does not include or require the separate pending-storage optimization.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 962c99c1-d30e-477f-9aa3-dff20c23a6b7

📥 Commits

Reviewing files that changed from the base of the PR and between 7253013 and f6e24d09af21dfd6de2629283a6a3f2d29851ee6.

📒 Files selected for processing (1)
  • config/reliability-gates.jsonc

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


📝 Walkthrough

Walkthrough

The terminal vertical-control scanner now jumps between ESC characters instead of scanning every code unit. New tests cover bounded inspections, CSI variants, embedded control strings, incomplete sequences, scan resumption, and redraw tail preservation. A new experimental reliability gate records coverage, test evidence, performance measurements, promotion criteria, and known gaps.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to f6e24

This change improves terminal control scanning performance while retaining parser behavior and adding focused regression coverage. The reliability-gate metadata now consistently reflects its supported coverage, so no merge-blocking current-head risk remains.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides a useful ELI5 summary, implementation details, performance data, and validation results. However, it omits most required template sections, including What Changed, Why, Linked… Complete the required template sections. Add the linked issue after "Fixes #"; add Visual Proof with attachments or write "N/A" and explain why; move testing details into Testing and mark the applicable checkboxes; complete AI Disclosure, R…
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 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: improving terminal preview control scans by skipping ordinary output.
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.
Full details: Description check

Explanation

The description provides a useful ELI5 summary, implementation details, performance data, and validation results. However, it omits most required template sections, including What Changed, Why, Linked Issue, Visual Proof, Testing checkboxes, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist.

Resolution

Complete the required template sections. Add the linked issue after "Fixes #"; add Visual Proof with attachments or write "N/A" and explain why; move testing details into Testing and mark the applicable checkboxes; complete AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist. Include clear What Changed and Why sections.

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. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)


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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Replaces the per-code-unit charCodeAt walk in containsTerminalVerticalLineControl with forward indexOf('\x1b') searches, adds a fidelity/work-budget test suite, and registers an experimental reliability gate.

  • containsTerminalVerticalLineControl: ESC detection now uses indexOf('\x1b', index + 1) instead of walking every code unit. The parseAnsiControlSequence call and the index = parsed.endIndex skip are unchanged, so recognition results are identical — each iteration still advances past the parsed control before searching for the next ESC.
  • New test file: 22 tests bound ordinary-text code-unit inspections (< 16 vs the ~90k baseline), pin CSI-A recognition across canonical/private/malformed forms, cover OSC/DCS/SOS/PM/APC embedding and incomplete controls, and exercise the tail redraw path end to end.
  • Reliability gate: terminal-performance.vertical-control-scan registered as experimental/partial with a work/fidelity oracle and recorded budget; schema-valid per config/scripts/check-reliability-gates.mjs.

I traced the indexOf rewrite against the original walk — including consecutive-ESC and OSC-terminator edge cases — and confirmed the search and skip semantics are equivalent. ESC is a single BMP code unit, so indexOf('\x1b') finds exactly the positions the charCodeAt scan did, and the loop still resumes at endIndex + 1 in both versions. The inspection-bound tests would fail loudly on a revert to the full walk, so they genuinely pin the optimization rather than absorbing it.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Re-reviewed the incremental delta (test-only plus gate metadata) on top of the previously approved optimization.

  • Scan-resumption tests: added 7 cases under resumes scanning after a parsed control that pin the index = parsed.endIndex skip interacting with indexOf('\x1b', index + 1) — an ESC inside CSI parameter bytes is consumed by that control, back-to-back controls resume correctly, an OSC (\x1b]0;t\x07) terminator is skipped before the next control, and a trailing lone ESC is reported false rather than looping.
  • Reliability gate metadata: oracle and assertion refs now include ESC-inside-params and back-to-back controls, and the evidence-run summary reflects the 29-test total.

I traced each new case against parseAnsiControlSequence and the indexOf loop and confirmed every expectation matches the implementation, and the full suite passes locally (29 tests). No production code changed, so no behavioral risk was introduced.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the nwparker/perf-terminal-vertical-control-scan-20260907 branch from 957b0d9 to 37b6c58 Compare September 8, 2026 06:37

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
config/reliability-gates.jsonc (1)

22-25: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Fix the self-contradictory coveredProviders claim for SSH/remote-runtime.

coveredProviders lists ssh and remote-runtime as covered. coverageNotes on the next line states the opposite: "live SSH transport and Linux/Windows runtime execution are not exercised." knownGaps later in the same gate repeats this: "Linux and Windows execution and live SSH transport have not been exercised." Remove ssh and remote-runtime from coveredProviders, or update coverageNotes/knownGaps to match the real test coverage. A stale coveredProviders value can mislead anyone using this manifest to judge whether the SSH/remote-runtime path is actually exercised.

Separately, this gate (agent-session.history-forward-read-budget) and the other scattered edits elsewhere in this diff are not mentioned in the PR summary or the AI-generated summary, which describe only one new gate for terminal-performance.vertical-control-scan. Confirm this gate is intentionally part of this change and not carried over from an unrelated branch state.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 01cb274f-c5b5-464e-8281-b4f428792143

📥 Commits

Reviewing files that changed from the base of the PR and between 957b0d9 and 37b6c58.

📒 Files selected for processing (1)
  • config/reliability-gates.jsonc

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.

@nwparker
nwparker force-pushed the nwparker/perf-terminal-vertical-control-scan-20260907 branch from 37b6c58 to 7253013 Compare September 9, 2026 02:51
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@nwparker
nwparker force-pushed the nwparker/perf-terminal-vertical-control-scan-20260907 branch 2 times, most recently from f6e24d0 to 389725f Compare September 9, 2026 10:32
@nwparker
nwparker force-pushed the nwparker/perf-terminal-vertical-control-scan-20260907 branch from 389725f to 7c5e0ff Compare September 9, 2026 10:41
@nwparker
nwparker merged commit 373a670 into main Sep 9, 2026
28 checks passed
fabolivark added a commit to ab2webco/orca-oss that referenced this pull request Sep 9, 2026
…s, and two hot-path walks (#371)

* fix(terminal): keep restored OSC-8 ranges across a no-op resize (#17759)

Cold restore seeded a checkpoint's OSC-8 link ranges and then replayed records
that resize, so any resize record after the checkpoint dropped them and
restored hyperlinks in scrollback lost clickability. Same-size resize records
reach the durable log routinely, because every attach re-asserts the pane's
dimensions and session-output-plane records each one without a same-size
dedupe — so an ordinary reattach was enough to lose the links.

Restored ranges are row-indexed, so clearing them on a reflow is right; a
resize to the size already applied is not a reflow. Gate on the dimensions
actually changing.

Introduced in d46349c ("fix: improve mobile link modifier handling",
#5597), which added setRestoredOscLinks along with unconditional clearing in
both resize() and clearScrollback(). clearScrollback's clearing is correct and
is unchanged, with a test pinning it.

Found during adversarial review of #17752 and filed as #17756. Not a
regression from that PR: #17667 had incidentally masked it by gating no-op
resizes to protect a snapshot cache, and removing the cache removed the gate.
The same gate returns here on its own terms — as a correctness fix with tests,
rather than as a side effect of a cache.

(cherry picked from commit ae35e04)

* fix(mobile): stop double-scaling commit timestamps in history rows (#17731)

Co-authored-by: Claude <[email protected]>
Co-authored-by: Jinwoo-H <[email protected]>
(cherry picked from commit c300913)

* perf(terminal): usar el trim que ya camina, no la regex cuadratica (upstream #19214)

Port de la idea de stablyai/orca#19214. Dos call sites del redraw seguian con
`line.replace(/[ \t]+$/g, '')`: el `+` anclado hace que el motor retroceda sobre
la corrida de padding por cada posicion de inicio que prueba, o sea tiempo
cuadratico en una fila que un TUI rellena hasta el ancho de la ventana. Y un
redraw a pantalla completa trimea CADA fila retenida en cada frame.

No hace falta traer nada: nuestro `trimTerminalLineRight` (orca-runtime.ts:39163)
ya camina la cadena y es identico al de upstream, solo que esos dos sitios nunca
lo usaron. El diff son dos lineas.

El test de upstream no se trae: importa `terminal-tail-buffer` y
`terminal-tail-line-controls`, dos modulos que extrajo despues de nuestra
divergencia, y nuestro helper es privado del monolito. Sin cambio de
comportamiento —las dos implementaciones son equivalentes, leidas lado a lado— y
los 4554 tests de `src/main/runtime` que cubren ese camino siguen verdes. La
medicion de la mejora es de upstream, no mia.

* perf(terminal): saltar a cada ESC en vez de caminar cada chunk (upstream #19400)

Port de stablyai/orca#19400 a nuestro monolito.
`containsTerminalVerticalLineControl` corre una vez por chunk de PTY, en el main
thread, para CADA terminal —visible, oculta o aparcada— y caminaba la cadena
posicion por posicion. Solo un ESC puede introducir un control vertical, asi que
para salida ordinaria (logs de build, `cat`, texto por pipe) el walk entero es
trabajo tirado.

Nuestra version era incluso mas lenta que la de upstream ANTES de su fix: leia
`value[index]`, que crea un string de un caracter por posicion. Ahora salta con
`indexOf` de ESC en ESC, conservando el skip de `parsed.endIndex` en el cuerpo.

4554 tests de `src/main/runtime` en verde, sin cambio de comportamiento.

---------

Co-authored-by: Neil <[email protected]>
Co-authored-by: blade035 <[email protected]>
Co-authored-by: Claude <[email protected]>
Co-authored-by: Jinwoo-H <[email protected]>
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