Skip to content

perf(sandbox): collapse runs of lines that differ only in numbers - #461

Merged
mrnasil merged 3 commits into
mainfrom
perf/collapse-similar-lines
Nov 24, 2026
Merged

mrnasil merged 3 commits into
mainfrom
perf/collapse-similar-lines

Conversation

@mrnasil

@mrnasil mrnasil commented Nov 24, 2026

Copy link
Copy Markdown
Member

Why

clean_terminal_output already folds identical repeated lines, but a test run prints thousands of lines like test case_N ... ok that differ only in N. In scripts/bench_tokens.py that one result (request 6) is ~12k tokens and every later request carries it again.

What

After the identical-line pass, a run of 8 or more lines whose shape matches once digit runs become # keeps its first and last line, with [N similar lines; only the numbers differ] between them.

  • A line that breaks the shape (test case_77 ... FAILED) ends the run and is kept.
  • Lines with no letters (CSV rows, bare numbers) are data and never collapse.
  • Shorter runs are left unchanged.

Measured (release, Windows, o200k, two-turn script)

Request 6 total Request 6 uncached Session total Session uncached
main 29,521 13,531 188,396 31,994
this PR 16,199 209 135,092 (−28%) 18,668 (−42%)

Checks

  • cargo test --lib for sandbox (63), agent (769), tools (538): all pass
  • fmt, clippy (sandbox), panic / swallowed-error / dependency / secrets ratchets

🤖 Generated with Claude Code

mrnasil and others added 3 commits November 24, 2026 19:15
Command output already folded runs of identical lines. A test run prints
thousands of `test case_N ... ok` lines that differ only in N, and every
later request carried them. A run of eight or more such lines now keeps
its first and last line with a count between. Lines that break the shape
(FAILED) are kept; lines of bare numbers are data and never collapse.

bench_tokens.py (two turns, o200k): session input 188,396 -> 135,092
(-28%), uncached 31,994 -> 18,668 (-42%).

Co-Authored-By: Claude Opus 5.5 <[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