Skip to content

perf(agents): cut process output into lines in linear time - #4217

Closed
LordMelkor wants to merge 3 commits into
block:mainfrom
LordMelkor:jello/linear-process-lines
Closed

LordMelkor wants to merge 3 commits into
block:mainfrom
LordMelkor:jello/linear-process-lines

Conversation

@LordMelkor

@LordMelkor LordMelkor commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

A person opening an 8.4 MB Goose transcript waits 1.17 s on main (down to 0.97 s here) and pays that read on every live refresh while the agent works (in Node, Goose's output callback drops from 317–376 ms to 12–18 ms, and a full refresh from 556–625 ms to 255–274 ms). Goose sends the whole session as one multi-MB line in 64 KiB pieces, and the line-splitting loop re-scanned the entire buffer on every piece; keeping the next line-end position checks an arriving piece only when no line end is buffered yet.

Size: +25/−12 production in three files — +9/−5 in core (acp/process.ts), +5/−1 in Pi (pi/pi.ts), and +11/−6 in Codex (codex/rpc.ts, which also resets the tracked position when reopening after an oversized line). Whole PR: +121/−12 with tests.

Why core, and how small

Core change Why a plugin cannot do it How small
Track next line-end position (acp/process.ts) Every ACP agent sends output through this host-owned loop; plugins receive lines only after they are cut. +9/−5: one private field and the loop using it; no new option or call

The Pi and Codex changes are inside their bundled plugins.

Numbers

In the app — Linux desktop (WebKitGTK, no GPU, debug build), real Goose, Pi, and Codex agents, synthetic sessions, three opens per build (click to first rows):

main This change
Goose, 8.4 MB session 1.14 to 1.19 s 0.96 to 0.98 s
Pi, 31 MB session 3.70 to 3.72 s 3.75 to 3.80 s
Codex, 48 MB session 3.84 to 3.95 s 3.83 to 3.88 s

Rows match main on every open (459, 1,392, and 3,734 rows). Pi and Codex show no app-open speedup because their opens are dominated by one drawing frame (3.4 s on Pi, 2.0 s on Codex), which #4181 addresses instead (Pi's 0.05 s difference sits inside that frame: 3.47–3.51 s vs 3.40–3.42 s, read 0.30 s vs 0.32 s).

In Node — real goose-acp 1.60.1, Pi host, and isolated ACP loop

Three runs of 11–12 refreshes each on the same sessions (turns, rows, and characters match main at every refresh):

main This change
Goose: output callback, per refresh 317 to 376 ms 12 to 18 ms
Goose: whole refresh 556 to 625 ms 255 to 274 ms
Pi: output callback, per refresh 76 to 90 ms 10 to 14 ms
Pi: whole refresh (after first of a run) 109 to 128 ms 43 to 76 ms
Pi: first refresh of a run 326 to 327 ms 246 to 248 ms
ACP loop alone: 2.1 MiB line in 64 KiB pieces 17 ms 1 ms
ACP loop alone: 4 MiB line 55 to 57 ms 2 ms
ACP loop alone: 9 MiB line 254 to 286 ms 3 to 5 ms
ACP loop alone: 9 MiB line in 16 KiB pieces 0.98 to 1.05 s 4 ms

Costs and what stays

  • Refresh timing scope: Live refreshes were timed in Node, not in the app.
  • Unchanged semantics & rest of refresh: Trimming, blank lines, CRLF, unfinished last lines, JSON parsing, and row mapping are unchanged (parsing and mapping make up the rest of refresh time).
  • 4 MiB Codex cap: The Codex client still refuses lines over 4 MiB (worst line cost ~57 ms before).
  • Untouched copies: Live Claude output and protected Claude transcript readers are unchanged (single-record lines; across 296 session files / 1.06 million records, max record is 2.1 MiB at 17 ms and none reaches 4 MiB). The execution-binding Codex relay loop is also unchanged (not used by the Transcript tab, no bundled plugin creates one, not run here).

Checks

  • At c40797c012: Codex 765 passed, 4 skipped; Pi 253 passed, 4 skipped; ACP client 70 passed. Both type checks and the design lane pass; trial merge with main is clean.
  • Review & lint: Agent review caught a stale line-end position on Codex reopen after an oversized line (fixed at head; without the reset, 3 existing Codex cases fail). landmines lint: 0 timing findings, 1 kept (shared fixture in tests/ beside other shared test helpers).

End-to-end test (AGENTS.md step 3)

An end-to-end test by the maintainer's agent on a separate Linux machine, made with human guidance from the maintainer driving this work.

  • Setup: pnpm tauri build --debug --no-bundle, local relay, throwaway identity, real Goose, Pi, and Codex agents, synthetic sessions.
  • Steps, scripted: Open each agent's Transcript tab three times per build, verify row count and sequence hash against main, time click to first rows, then send a live Goose prompt and watch the turn move from Working to Completed.
  • Result: See the app table above. Goose and Pi ran at cd5b2e622 (one commit before head; the final commit touches Codex files only), and Codex ran at head.
New tests

One shared fixture cuts a reply at every position, one character at a time, with CRLF, blank lines, padding, and an unfinished record, feeding it through the real ACP client, Pi host, and Codex client. Output must match for every cut; four single off-by-one mutations each break a case.

🤖 Generated with Claude Code

LordMelkor and others added 3 commits November 21, 2026 23:43
Co-authored-by: Jello <c9085e5557728e0eb4eba927ae283fb1f27e65319dfa77e2ee2125e2cba7042d@buzz.block.builderlab.xyz>
Signed-off-by: LordMelkor <kray@squareup.com>
Co-authored-by: Jello <c9085e5557728e0eb4eba927ae283fb1f27e65319dfa77e2ee2125e2cba7042d@buzz.block.builderlab.xyz>
Signed-off-by: LordMelkor <kray@squareup.com>
Co-authored-by: Jello <c9085e5557728e0eb4eba927ae283fb1f27e65319dfa77e2ee2125e2cba7042d@buzz.block.builderlab.xyz>
Signed-off-by: LordMelkor <kray@squareup.com>
@LordMelkor
LordMelkor requested a review from a team as a code owner November 22, 2026 06:27
@LordMelkor

Copy link
Copy Markdown
Contributor Author

🤖 Closing this one. It does not clear the bar we hold every speed change to: about one second less waiting plus frozen time on something a person does in the app.

Measured in the app (Linux desktop, WebKitGTK, debug build, real Goose agent, synthetic 8.4 MB session, three journeys per build, interleaved). The journey: open the Transcript tab, send one prompt, watch the turn until it shows Completed. Waiting plus frozen time is the open wait plus every frame of 100 ms or more.

main This change
Waiting plus frozen time, median (range) 2.30 s (2.18 to 2.38) 2.04 s (1.91 to 2.04)
Open wait 1.23 s 1.06 s
Frozen time 1.07 s 0.95 s
Turn length 49.7 s 48.3 s

That is 0.26 s on a journey of about 50 s. Pi and Codex opens did not change (table in the description).

Not measured in the app: after an app restart a Goose turn runs in a new session, so the tab holds 10 rows at the end of this journey, and the journey never refreshes a long session that is still working. The Node numbers in the description (output callback 317–376 ms → 12–18 ms per refresh) cover that case and stand as measured in Node only.

The change is correct and small (+9/−5 in core), but 0.26 s does not earn a maintainer's review. The branch stays in case a long live Goose or Pi session ever shows this cost in the app.

@LordMelkor LordMelkor closed this Nov 22, 2026
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