Skip to content

perf(terminal): release oversized backing strings behind pending controls - #19396

Merged
nwparker merged 4 commits into
mainfrom
nwparker/perf-pending-control-storage-20260907
Sep 9, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/perf-pending-control-storage-20260907

Conversation

@nwparker

@nwparker nwparker commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​346 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​346
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​174 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​171

ELI5

When a terminal is partway through receiving a special marker — an agent status update or a window title — and that marker gets cut in half between two batches of output, Orca has to hold onto the half it already has until the rest shows up. Because of how JavaScript stores pieces of text, hanging onto that tiny fragment could quietly keep the entire batch of output it was cut from — sometimes several megabytes — alive in memory for as long as the terminal sat idle. This change makes Orca take a small standalone copy of just the fragment, so the big batch of output behind it can be thrown away. Taking that copy turns out to be cheap enough (about a microsecond) that Orca now just always does it, instead of trying to guess when it is worth it — the guessing was what made it expensive.

What this does

bigChunk.slice(a, b) is a V8 SlicedString that pins the whole parent. Three places keep a small fragment of a consumed PTY chunk across calls, so an idle terminal could pin megabytes:

  • src/shared/agent-status-osc.ts — the pending OSC 9999 frame.
  • src/main/runtime/terminal-ansi-normalization.ts — pendingAnsi.
  • src/shared/osc-title-scan-tail.ts — the incomplete title tail.

New src/shared/own-retained-string.ts exports ownRetainedString(value), applied unconditionally at all three sites.

Why the design changed

The first revision of this PR reused copyUtf16SuffixToOwnedString, which copies unit-by-unit through an array plus String.fromCharCode(...spread). Measured (min of 12 rounds × 500, isolated processes, two-byte input with a lone surrogate):

N (code units) charCodeAt block copier Buffer.from(s,'utf16le').toString('utf16le')
4 Ki 10.0 µs 0.57 µs
64 Ki 170.3 µs 21.9 µs

Because the copy was slow, the first revision gated it behind "copy only when discarded content dominates the retained tail". That gate was the actual cost problem, not the copy: it fires on every chunk of an adversarial stream and pays the slow copy each time. Interleaved min-of-15 comparisons against the un-owned parsers (µs per chunk):

Workload un-owned base gate + block copier unconditional + Buffer
ANSI, 16 Ki-char chunks, 4 Ki tail (cap) 48.7 70.8 (+45.3%) 50.1 (+2.8%)
ANSI, 4 Ki-char chunks, 2 Ki tail 14.7 20.1 (+36.9%) 12.9 (−12.0%)
Status, 194 Ki-char chunks, 64 Ki frame (cap) 298.1 628.8 (+111.0%) 360.5 (+21.0%)

A second run reproduced the direction (+15.0% / +81.2% for the gate; −3.6% / −7.6% for unconditional ownership). Streams with no pending control never call the primitive at all.

So the gate is gone. N is already capped at 4 Ki (ANSI/title) and 64 Ki (status), and at ~1 µs per copy unconditional ownership costs less than the parser's own scan. Dropping it also removes the sub-13-unit waste: ownRetainedString returns anything shorter than V8's SlicedString::kMinLength (13) unchanged, because such a slice is already flat.

Buffer is unavailable in the renderer and on mobile, and agent-status-osc.ts runs in both. The copier is resolved once behind a lone-surrogate round-trip self-check and falls back to the existing block copier; a test asserts the two are byte-identical.

Retention evidence

Forced-GC probe, 32 × 1 Mi parents each pinned by one 4 Ki tail:

  • plain slices: 32.00 MB retained
  • ownRetainedString: 1.13 MB retained

Tests

The three flake-prone forced-GC threshold fixtures are replaced by:

  • one forced-GC test for the primitive itself (src/shared/own-retained-string.test.ts), with both an absolute bound and a relative owned < sliced / 8 bound;
  • deterministic vi.spyOn(ownership, 'ownRetainedString') assertions that each retention site routes its retained value through the primitive on every chunk, including growing fragments.

The "no repeated copy while a fragment grows" test is deleted: re-owning a growing fragment on every chunk is now the intended contract.

All fidelity and differential coverage is kept — exact UTF-16, lone and split surrogates through BEL/ST completion, introducer-preserving ANSI/title trimming at and past the cap, payload ordering, and clean-output offsets.

Red/green: removing ownRetainedString from terminal-ansi-normalization.ts fails the spy assertion while all ten fidelity cases still pass, confirming the retention contract is carried by the new assertions.

Validation

  • pnpm test on the gate's nine files: 114 passed.
  • src/renderer/src/components/automations: 101 files / 796 tests passed (the pre-existing copyUtf16SuffixToOwnedString consumer is untouched).
  • oxlint clean; pnpm run check:code-quality:changed: 0 new findings across 8 files; pnpm tc:web clean.
  • node config/scripts/check-reliability-gates.mjs: passed for 110 gates.

Reliability gate terminal-performance.pending-control-storage is updated to the new oracle. Execution authority, folder/git identity, wire formats and mobile UI are unchanged. Live Electron/native Linux/Windows/WSL/SSH measurement, production incidence and whole-process memory impact remain unmeasured; already-sliced provider input can hide a larger ancestor, so this is not a universal heap cap.

Follow-up

The pending tails fixed here pin at most one chunk per PTY. The far larger instance of the same pattern is appendNormalizedToTailBuffer, which retains up to 2000 rows each sliced from its chunk. That is handled in a separate follow-up PR.

This PR is independent of the forward-search optimization in #19373 and the other performance fixes; its status parser retains the original terminator-search algorithm.

@coderabbitai

coderabbitai Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview 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: a1923e90-7514-4e3a-9c2b-047c6ab5de11

📥 Commits

Reviewing files that changed from the base of the PR and between feb81fa and 5c55b92ad41dedcc292fa0b100e1a8e398c4a62b.

📒 Files selected for processing (2)
  • config/reliability-gates.jsonc
  • src/shared/own-retained-string.ts

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


📝 Walkthrough

Walkthrough

Pending ANSI, OSC status, and OSC title parsers now re-own retained UTF-16 tails when consumed input is substantially larger than the retained tail. New tests cover bounded memory retention, UTF-16 preservation, control completion, and copy avoidance. An experimental reliability gate records coverage, invariants, validation results, performance budgets, known gaps, and promotion or demotion criteria.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 5c55b

This change makes retained terminal control fragments own their own string storage so large PTY chunks can be released, reducing memory growth. Behavior for ordinary terminal output is unchanged. Two known follow-ups remain: one input shape (a chunk ending in a lone escape) can still hold on to its oversized buffer, and the over-limit drop path for pending status frames is not yet exercised by a test. Mergeable with owner awareness of those follow-ups.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change, motivation, implementation, testing, limitations, and follow-up work. However, it omits several required template sections, including the linked issue, explicit vi… Add the missing required sections and information. Provide a linked issue after “Fixes #”. Add “Visual Proof” with N/A and a reason if there is no visual or interaction change. Add AI Disclosure details when applicable. Complete “Review”,…
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 8 files. (1 skipped: … 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 identifies the terminal performance change and the release of oversized backing strings retained by pending controls.
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 explains the change, motivation, implementation, testing, limitations, and follow-up work. However, it omits several required template sections, including the linked issue, explicit visual-proof status, AI Disclosure, Review, Agent skill upstream boundary, Notes, and the Checklist. It also uses “What this does” instead of the required “What Changed” heading.

Resolution

Add the missing required sections and information. Provide a linked issue after “Fixes #”. Add “Visual Proof” with N/A and a reason if there is no visual or interaction change. Add AI Disclosure details when applicable. Complete “Review”, “Agent skill upstream boundary”, “Notes”, and all relevant Checklist items. Rename “What this does” to “What Changed” or add the required heading.

Full details: Docstring Coverage

Explanation

Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 8 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@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)
src/main/runtime/terminal-ansi-normalization.ts (1)

103-103: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Copy a lone trailing escape before storing it.

Line 103 stores combined.slice(index) when a large chunk ends in only \x1b. That one-code-unit pending tail can retain the full combined backing string. Apply the same ownership condition in this branch. Add a regression case for a large prefix followed by \x1b.

Proposed fix
       if (index + 1 >= combined.length) {
-        return { text: parts.join(''), pendingAnsi: combined.slice(index) }
+        const pendingAnsi = combined.slice(index)
+        return {
+          text: parts.join(''),
+          pendingAnsi:
+            combined.length > pendingAnsi.length * 2
+              ? copyUtf16SuffixToOwnedString(pendingAnsi, pendingAnsi.length)
+              : pendingAnsi
+        }
       }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 7e3ba109-c3be-4dc1-b5d2-18bb99c0ff6d

📥 Commits

Reviewing files that changed from the base of the PR and between 9f04403 and f900dcf.

📒 Files selected for processing (7)
  • config/reliability-gates.jsonc
  • src/main/runtime/terminal-ansi-normalization.ts
  • src/main/runtime/terminal-ansi-pending-retention.test.ts
  • src/shared/agent-status-osc-pending-retention.test.ts
  • src/shared/agent-status-osc.ts
  • src/shared/osc-title-scan-tail-retention.test.ts
  • src/shared/osc-title-scan-tail.ts

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

@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 critical issues — one minor manifest nit inline.

Reviewed changes

  • Owned-suffix release for three pending-control paths — agent-status-osc.ts, terminal-ansi-normalization.ts, and osc-title-scan-tail.ts now copy their retained pending tails through the existing copyUtf16SuffixToOwnedString only when discarded output dominates the tail, breaking the sliced-string retention of oversized backing buffers without recopying growing fragments.
  • Retention test suites — three new forced-GC suites assert retained heap stays under 2 MiB while continuations complete faithfully, surrogate pairs survive, and 512-unit growth triggers no copies.
  • Reliability gate — a new terminal-performance.pending-control-storage experimental gate records the invariant, oracle, red/green evidence, and known gaps.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

"coveredProviders": ["local", "daemon", "ssh", "remote-runtime"],
"coverageNotes": "Shared code-unit and production normalizer/parser tests cover provider-independent behavior on macOS; existing buffer contracts cover normalized output. Native execution, process ownership, wire formats and mobile UI are unchanged. Folder/git identity is not inspected by these string functions.",
"motivatingLinks": [
"https://github.com/stablyai/orca/blob/main/src/shared/agent-status-osc.test.ts"

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.

motivatingLinks points at a source test file; every other gate in this manifest links the issue or PR that motivated the work. Consider linking the tracking issue/PR here instead.

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

Important

The new src/shared/own-retained-string.ts embeds a literal NUL byte in its ROUND_TRIP_PROBE string, so git classifies the file as binary — the entire primitive is invisible in the GitHub diff and in every future diff that touches it. Escape the NUL (\u0000) before merging.

Reviewed changes

  • Replaced the gated block copier with an unconditional ownRetainedString primitive — a Buffer.from(value, 'utf16le').toString('utf16le') round trip, resolved once behind a lone-surrogate self-check with a code-unit block-copier fallback for renderer/mobile, now applied unconditionally at all three pending-control sites (dropping the ~2x discarded-dominates gate).
  • Reworked the retention tests — the three flake-prone forced-GC suites became deterministic vi.spyOn(ownership, 'ownRetainedString') assertions, plus a single forced-GC test for the primitive itself (32 × 1 Mi parents vs 4 Ki tails), byte-exact round-trip cases, and a Buffer-free fallback equivalence check.
  • Updated the reliability gate — terminal-performance.pending-control-storage now documents the new oracle, red/green evidence, performance budget, and known gaps.

⚠️ New primitive file is committed as binary

src/shared/own-retained-string.ts contains a raw NUL byte (0x00) inside the ROUND_TRIP_PROBE string literal, so git classifies the file as binary. git diff --stat reports Bin 0 -> 1715 bytes, and the PR diff shows "Binary files ... differ" — the 46 lines of the primitive this entire change routes through are not visible to reviewers, and every future change to the file will also render as an opaque blob.

Technical details
# Escape the NUL byte in ROUND_TRIP_PROBE so the file diffs as text

## Affected sites
- src/shared/own-retained-string.ts — `const ROUND_TRIP_PROBE = '\ud800a\udfff<0x00>漢'` (raw NUL between `\udfff` and `漢`).

## Required outcome
- The file must not contain a raw NUL byte; git must classify it as text and render its contents in the PR diff.
- Runtime behavior unchanged: the probe still exercises the lone lead surrogate `\ud800`, unpaired trail `\udfff`, NUL code unit, and a two-byte BMP char across the `utf16le` round trip.

## Suggested approach
- Rewrite the literal as `'\ud800a\udfff\u0000漢'` (escape the NUL; optionally `\u6f22` for `漢`). Behavior-identical, since a raw NUL and `\u0000` are the same code unit inside a JS string.

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

@nwparker
nwparker force-pushed the nwparker/perf-pending-control-storage-20260907 branch from cf28130 to 430a5fb Compare September 8, 2026 06:35
nwparker added a commit that referenced this pull request Sep 8, 2026
Every row in the 2000-row retained tail is sliced from the PTY chunk it
arrived in, so a spinner workload — CR-redraw frames, exactly what Claude
Code and Codex emit — makes a ~5 KB tail pin one whole chunk per row.
Measured on 400 x 64 Ki-char chunks: a 5,090-char tail retained 37.5 MB.
At 16 Ki x 1600 it was 46.9 MB.

Own the two values the plain tail path actually retains, newlyCompletedLines
and the partial line, at the point they enter the tail: 37.5 MB -> 0.18 MB
and 46.9 MB -> 0.09 MB, with per-chunk cost unchanged within noise. The
transcript keeps the same row objects, so it is covered transitively.

The multiline redraw builder never slices normalizedChunk — it writes rows
character by character — so only its partial line, which is re-sliced from
its own row on every frame, needs owning. Owning its rows as well measured
no retention gain and cost CPU on fullscreen TUI floods.

Also own the wait-blocked keywordCarry: 31 characters that pinned a full
lowercased copy of the chunk, per PTY.

Follow-up to #19396, which introduced ownRetainedString for the much smaller
pending-control fragments.

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: e2b24c81-3402-41ad-b61d-be7c94e8904a

📥 Commits

Reviewing files that changed from the base of the PR and between f900dcf and 430a5fb.

📒 Files selected for processing (9)
  • config/reliability-gates.jsonc
  • src/main/runtime/terminal-ansi-normalization.ts
  • src/main/runtime/terminal-ansi-pending-retention.test.ts
  • src/shared/agent-status-osc-pending-retention.test.ts
  • src/shared/agent-status-osc.ts
  • src/shared/osc-title-scan-tail-retention.test.ts
  • src/shared/osc-title-scan-tail.ts
  • src/shared/own-retained-string.test.ts
  • src/shared/own-retained-string.ts

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

Comment on lines +75 to +77
const pending = marker + ' '.repeat(64 * 1024 - marker.length)
for (let offset = 0; offset < pending.length; offset += 512) {
process(pending.slice(offset, offset + 512))

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Exercise the over-cap branch.

pending has exactly 64 * 1024 code units, so the processor retains it because the drop condition is strictly greater than MAX_PENDING. Add one code unit before the terminator. Then assert cleanData: '\x07after', payloads: [], and lastPayloadCleanOffset: null.

@nwparker
nwparker force-pushed the nwparker/perf-pending-control-storage-20260907 branch from 430a5fb to feb81fa Compare September 9, 2026 02:49
@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 added a commit that referenced this pull request Sep 9, 2026
Every row in the 2000-row retained tail is sliced from the PTY chunk it
arrived in, so a spinner workload — CR-redraw frames, exactly what Claude
Code and Codex emit — makes a ~5 KB tail pin one whole chunk per row.
Measured on 400 x 64 Ki-char chunks: a 5,090-char tail retained 37.5 MB.
At 16 Ki x 1600 it was 46.9 MB.

Own the two values the plain tail path actually retains, newlyCompletedLines
and the partial line, at the point they enter the tail: 37.5 MB -> 0.18 MB
and 46.9 MB -> 0.09 MB, with per-chunk cost unchanged within noise. The
transcript keeps the same row objects, so it is covered transitively.

The multiline redraw builder never slices normalizedChunk — it writes rows
character by character — so only its partial line, which is re-sliced from
its own row on every frame, needs owning. Owning its rows as well measured
no retention gain and cost CPU on fullscreen TUI floods.

Also own the wait-blocked keywordCarry: 31 characters that pinned a full
lowercased copy of the chunk, per PTY.

Follow-up to #19396, which introduced ownRetainedString for the much smaller
pending-control fragments.
@nwparker
nwparker force-pushed the nwparker/perf-pending-control-storage-20260907 branch from feb81fa to 5c55b92 Compare September 9, 2026 10:22

@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. The NUL-escape fix is clean and resolves the prior binary-file finding; the only thing keeping this from approval is a still-open earlier nit on config/reliability-gates.jsonc (motivatingLinks still points at src/shared/agent-status-osc.test.ts rather than the tracking issue/PR).

Reviewed changes

  • Escaped the NUL byte in the round-trip probe — src/shared/own-retained-string.ts now writes ROUND_TRIP_PROBE as '\ud800a\udfff\u0000\u6f22', so the file no longer contains a raw NUL and git renders it as a normal text diff instead of Bin 0 -> 1715 bytes. Runtime behavior is unchanged, since a raw NUL and \u0000 are the same code unit inside a JS string.

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

nwparker and others added 4 commits September 9, 2026 03:31
…tive

The pending-control ownership landed with a charCodeAt block copier (10 us
at 4 Ki, 170 us at 64 Ki), so it needed a "copy only when discarded output
dominates the tail" gate to stay affordable. That gate was the whole cost
problem: on adversarial streams it fires every chunk and pays the slow copy
(+45% on 16 Ki ANSI chunks, +81..111% on 194 Ki status chunks), and it also
skipped ownership on fragments too small to be sliced strings anyway.

ownRetainedString replaces it with a Buffer utf16le round trip (0.57 us at
4 Ki, 21.9 us at 64 Ki) and returns anything below V8's SlicedString
kMinLength unchanged. Buffer is absent in the renderer and on mobile, so the
copier is resolved once behind a lone-surrogate round-trip self-check and
falls back to the block copier. With a ~1 us copy the gate is unnecessary:
ownership is now unconditional at all three retention sites and the
adversarial cases land within noise of the un-owned parsers.

The three forced-GC threshold fixtures are replaced by one forced-GC test
for the primitive plus deterministic spy assertions that each site routes
its retained value through ownRetainedString. All fidelity and differential
coverage is kept.
A raw NUL byte in the source made git treat the file as binary, so its
diffs and blame were unreadable. Escapes are equivalent at runtime.
@nwparker
nwparker force-pushed the nwparker/perf-pending-control-storage-20260907 branch from 5c55b92 to 75400fc Compare September 9, 2026 10:31
@nwparker
nwparker merged commit 1e2ed20 into main Sep 9, 2026
28 checks passed
nwparker added a commit that referenced this pull request Sep 9, 2026
Every row in the 2000-row retained tail is sliced from the PTY chunk it
arrived in, so a spinner workload — CR-redraw frames, exactly what Claude
Code and Codex emit — makes a ~5 KB tail pin one whole chunk per row.
Measured on 400 x 64 Ki-char chunks: a 5,090-char tail retained 37.5 MB.
At 16 Ki x 1600 it was 46.9 MB.

Own the two values the plain tail path actually retains, newlyCompletedLines
and the partial line, at the point they enter the tail: 37.5 MB -> 0.18 MB
and 46.9 MB -> 0.09 MB, with per-chunk cost unchanged within noise. The
transcript keeps the same row objects, so it is covered transitively.

The multiline redraw builder never slices normalizedChunk — it writes rows
character by character — so only its partial line, which is re-sliced from
its own row on every frame, needs owning. Owning its rows as well measured
no retention gain and cost CPU on fullscreen TUI floods.

Also own the wait-blocked keywordCarry: 31 characters that pinned a full
lowercased copy of the chunk, per PTY.

Follow-up to #19396, which introduced ownRetainedString for the much smaller
pending-control fragments.
nwparker added a commit that referenced this pull request Sep 9, 2026
…nks (#19528)

Every row in the 2000-row retained tail is sliced from the PTY chunk it
arrived in, so a spinner workload — CR-redraw frames, exactly what Claude
Code and Codex emit — makes a ~5 KB tail pin one whole chunk per row.
Measured on 400 x 64 Ki-char chunks: a 5,090-char tail retained 37.5 MB.
At 16 Ki x 1600 it was 46.9 MB.

Own the two values the plain tail path actually retains, newlyCompletedLines
and the partial line, at the point they enter the tail: 37.5 MB -> 0.18 MB
and 46.9 MB -> 0.09 MB, with per-chunk cost unchanged within noise. The
transcript keeps the same row objects, so it is covered transitively.

The multiline redraw builder never slices normalizedChunk — it writes rows
character by character — so only its partial line, which is re-sliced from
its own row on every frame, needs owning. Owning its rows as well measured
no retention gain and cost CPU on fullscreen TUI floods.

Also own the wait-blocked keywordCarry: 31 characters that pinned a full
lowercased copy of the chunk, per PTY.

Follow-up to #19396, which introduced ownRetainedString for the much smaller
pending-control fragments.
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