Skip to content

perf(runtime): chunk captured non-ASCII output on UTF-8 byte boundaries - #949

Merged
kvlonge merged 1 commit into
mainfrom
perf/output-capture-chunking
Oct 5, 2026
Merged

kvlonge merged 1 commit into
mainfrom
perf/output-capture-chunking

Conversation

@kvlonge

@kvlonge kvlonge commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Why

Command-output capture split any line over 64 KiB that contained non-ASCII text one character at a time in Python. Large --json compile reports with non-ASCII SQL literals spent about 0.3–0.9 s there, on full and reused compiles alike (CHI-504).

Changes

  • Encode non-ASCII text to UTF-8 once and cut chunks on character boundaries by stepping back over continuation bytes; the ASCII fast path and the fallback for lone surrogates are unchanged.
  • Chunk sizes, boundaries, rejoined text and raised exceptions are identical to before.

Verification

  • Chunking 10 MB of non-ASCII text: 875 → 22 ms. A 120-model DuckDB compile with a 9.8 MB report: 2.67 → 1.74 s wall (full) and 2.42 → 1.46 s (reused).
  • Randomised equality test against a copy of the previous implementation, boundary cases and a speed guard; the reviewer also fuzzed 200,000 strings against main with zero mismatches.
  • One independent review; make test, make check-ci.

Command-output capture split any line over the record limit that
contained non-ASCII text one character at a time in Python. Encode the
line once, slice greedily at the last code point boundary within each
limit, and decode each slice. Chunk boundaries and text are unchanged;
lines with lone surrogates keep the original character-by-character
path because surrogateescape bytes are not valid UTF-8.

Closes CHI-504.
@kvlonge
kvlonge enabled auto-merge (squash) October 5, 2026 16:27
@kvlonge
kvlonge merged commit e697cd9 into main Oct 5, 2026
22 checks passed
@kvlonge
kvlonge deleted the perf/output-capture-chunking branch October 5, 2026 16:41
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