perf(shared): count terminal resume lines without allocations #28539
main fromrefs/pull/28539/head·merged by maria-rcks View on GitHubProblem#
terminalOutputResumeText splits all output into a line array just to compute a count capped at 64. Reconnecting a viewer allocates O(n) temporary space for scrollback that cannot affect cursor reachability.
Solution#
Count newline positions with a forward cursor and stop after 63 matches. Line counting now uses O(1) auxiliary space, with no worse O(n) time. The required resume output stream remains O(n); this is not a whole-pipeline memory claim.
Empty output, trailing newlines, saved cursors, trimmed tails, style state, and partial escapes keep the same behavior. This small performance fix changes no contracts or persisted state. It is separate from #26691, which improves tail folding rather than resume line counting.
Verification:
- A verifier written and run before implementation checks 1,090 baseline/resync scenarios and exact cap boundaries. Every result matches main
7195b69954. - Large-scrollback cases create no split array and make at most 63 newline searches. These are operation counts, not a latency benchmark.
vp test run packages/shared/src/terminalOutput.test.ts: 16 pass before and after.vp run check:changed: clean, including 17 selected tests. Three independent Codex reviews: clean.- Repeatable verifier, original module, failure matrix, and logs. No live client session or real model call.
TLDR#
https://github.com/user-attachments/assets/b0622963-3c32-463c-b217-727ef1440bac
Narrated explanation of the allocation change and reconnect parity checks.
Code and reviews: GPT-6.1 Sol through the Codex harness.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Approvability#
Verdict: Approved at
6791f6bMacroscope's review found this PR approvable — This replaces allocated line splitting with a bounded newline scan when rebuilding terminal resume output. Existing cursor limits and output behavior remain unchanged, with no material expansion in exposure.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
No actionable comments were generated in the recent review.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 7195b69
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
13c90677-c9a1-4728-a83c-5147b097b214
Commits-
Reviewing files that changed from the base of the PR and between 7195b699547b538e49f758e314dde5c8c5d907cf and 6791f6b981f86b58bdf9eb8af914d44cccd8c4b1.
Files selected for processing: 1-
packages/shared/src/terminalOutput.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
Walkthrough
-
terminalOutputResumeTextnow counts newline characters instate.textto determine reachable rows, stopping atLIVE_LINES - 1or when no more newlines remain.Changes: Terminal resume
Layer / File(s) Summary Count reachable rows
packages/shared/src/terminalOutput.tsterminalOutputResumeTextcounts newline characters up toLIVE_LINES - 1instead of splitting the text and capping the displayed-line count.Estimated code review effort: 1 (Trivial) | ~5 minutes
Change: Refactor
Suggested reviewers:
maria-rcks
Merge Risk:
Minimal · up to6791f-
The optimization preserves terminal resume behavior and introduces no identified merge-blocking risk.
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly and concisely describes the main performance change: counting terminal resume lines without allocations. Description check The description explains the problem, solution, behavior preservation, and verification results. It does not include a distinct "Scope and approval" section or explicit approval or exemption justifica… Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Full details: Description check
-
Explanation
The description explains the problem, solution, behavior preservation, and verification results. It does not include a distinct "Scope and approval" section or explicit approval or exemption justification, but it is otherwise substantially complete.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Action not completed
-
Already reviewed the last commit. Use
@coderabbitai full reviewto rerun a review of the entire changeset.Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
-
Note
Written by
gpt-6.1-solon behalf of MariaVerified in a real dev environment#
verified head
6791f6b981f86b58bdf9eb8af914d44cccd8c4b1againstgithub/mainat37d7615a91on linux. used separate checkouts, one dev server at a time, repository playwright with google chrome, an app-created git project/thread, and real codexgpt-6.1-solturns. no mocks or replay data.- reproduced main's allocation through the live command output viewer: a 22,971-character tail split into 2,011 array entries; a 65,530-character tail split into 5,469 entries.
- on this head, reopening the same 22,971-character tail made 63 newline searches. reopening the 65,530-character trimmed tail also made 63 searches. an external runtime observer recorded calls only from
terminalOutputResumeText; repository source was unchanged. these are operation counts, not latency or whole-pipeline memory measurements. - collapsed/reopened running output and reloaded the page. output resumed and advanced through 40 batches / 8,000 numbered lines to
RESUME-DONE. the trimmed-output notice remained visible. completed output also reopened with the final marker intact. - another real command exercised green style state, saved-cursor/carriage-return updates, and reopening during an eight-second partial escape. output continued with green
STATUS tick 10, redPARTIAL-ESCAPE-RED, and plainANSI-DONE. - blacksmith: 24 focused terminal/output-hub tests passed.
vp run check:changed HEAD^passed format, lint, knip, affected typechecks, and 17 selected tests. existing github checks are green. no fixes or commits needed.
command transcript and runtime observations




Not verified#
native desktop and ios/android clients, macos/windows behavior, relay/tunnel connections, and other providers were not exercised on this linux vm. no end-to-end latency or total memory claim. uploaded video playback and seeking were checked in the t3 browser.
@maria-rcks thanks for the live verification and the clear scope limits. No fixes are needed from your report. Checks are green on
6791f6b, CodeRabbit has been quiet for more than 15 minutes, and there are no unresolved review threads. Could you leave a formal PR review when ready? Related: #26691 optimizes streaming tail folding; this PR separately removes the temporary line array during resume, so the two changes are complementary.maria-rcks merged this6ef66b6
maria-rcks closed this
Sign in to join this conversation.
@coderabbitai review