Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(shared): count terminal resume lines without allocations #28539

Mergedhieu-lee(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/28539/headmerged by maria-rcks View on GitHub

Problem

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

    2. Approvability

      Verdict: Approved at 6791f6b

      Macroscope'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).
    3. Review in Change Stack →

      No actionable comments were generated in the recent review.

      Recent review info
      Run configuration
      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

      terminalOutputResumeText now counts newline characters in state.text to determine reachable rows, stopping at LIVE_LINES - 1 or when no more newlines remain.

      Changes: Terminal resume

      Layer / File(s)Summary
      Count reachable rows
      packages/shared/src/terminalOutput.ts
      terminalOutputResumeText counts newline characters up to LIVE_LINES - 1 instead 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 to 6791f

      The optimization preserves terminal resume behavior and introduces no identified merge-blocking risk.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main performance change: counting terminal resume lines without allocations.
      Description checkPassedThe 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 checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck 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
    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Action not completed

      Already reviewed the last commit. Use @coderabbitai full review to 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.

    5. maria-rckscommented

      Note

      Written by gpt-6.1-sol on behalf of Maria

      Verified in a real dev environment

      verified head 6791f6b981f86b58bdf9eb8af914d44cccd8c4b1 against github/main at 37d7615a91 on linux. used separate checkouts, one dev server at a time, repository playwright with google chrome, an app-created git project/thread, and real codex gpt-6.1-sol turns. 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, red PARTIAL-ESCAPE-RED, and plain ANSI-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

      main: running numbered command output before the allocation change

      pr: restored trimmed output continues receiving numbered batches

      pr: saved cursor and partial escape preserve green and red output

      pr: recording of collapse, reopen, and subsequent live output

      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.

    6. @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.

    7. maria-rcks merged this6ef66b6

    8. maria-rcks closed this

Sign in to join this conversation.