Repository navigation
perf(cat,wc): i18n length gate + wc ASCII fast path (1.41x/1.44x -> floor/0.64x vs MSYS) - #1533
Conversation
…(refs PERF-BASELINE)
cat 64MiB: 0.318s -> 0.122s (-62%, at the engine copy floor; the
translate_legacy FNV-1a hash + 3 heap allocs ran over every 64KiB
block although legacy catalog keys are short literals - the longest
across the tree is 92B, the zh-CN catalog's 1061 keys top out at 59B,
so >256B text can never be a key. Class-level invariant, gated inside
translate_legacy, not bypassed in cat.)
wc 64MiB: 0.409s -> 0.243s (0.64x vs MSYS GNU, was 1.07x): a 7-bit
ASCII fast loop byte-mirrors consume_codepoint's ASCII branch and
hands control back to the UTF-8 decoder at the first >=0x80 byte,
sharing word/line/width state; carry across chunk borders unchanged.
Correctness: 315-case three-way differential (wc: 12 fixtures x 12
option sets x {GNU 5.3.20, pre, post} + 15 cat payload md5s) - zero
divergence, pre == post == GNU; under a real zh-CN catalog wc short
lines still translate and cat bulk output stays byte-identical.
Unit tests: wc 32/32, winuxcmd i18n 2/2, 4 new cases; cat 44/45 with
the one failure (nul_txt_reads_file_issue1333) reproduced on the
unmodified base build - pre-existing environment flake, not this
diff. Full method and tables in PERF-BASELINE.md (after-fix section).
|
Captain review — verdict: CAN MERGE. I read the full diff (5 files, 437 lines) and the CI is now fully green Content. The two fixes are sound and the numbers hold up:
CI. The first differential run's oracle failure was a savannah Notes for the merge (not blockers):
Merge decision is the user's / Windows side's — I am not merging. |
The rust2 bridge drained Rust stdout/stderr through safePrint / safeErrorPrint, which apply the legacy i18n catalog lookup (translate_legacy) to the whole payload. For true/false (no output) that was unobservable, but a data-printing command — basename's result line, printenv's value, pwd's path — must reach the handle byte-for-byte: an entry whose FNV-1a key hashes to the output bytes would otherwise silently replace command DATA. The #1533 length gate only narrows the lookup; a data output path has to bypass translation entirely. Add safePrintRaw / safeErrorPrintRaw (mirrors of the translating writers minus translate_legacy, sharing capture handles, console/file detection, byte counting, SIGPIPE mapping and write-failure notes) and route the bridge's drain through them. - src/utils/console.cppm: add the two raw writers next to the UTF-8 overloads they mirror. - src/bridge/rust2_bridge.cppm: drain through the raw writers; comment states why translation must not apply here. Refs #1488
Follow-up to the PERF-BASELINE.md hotspots (branch perf/baseline-sweep, method + raw data in the same tree).
src/utils/i18n.cppm): gatetranslate_legacyat 256B — catalog legacy keys are source-literal short strings (longest in-tree 92B, zh-CN's 1061 keys max 59B), so hashing a whole 64KiB buffer was guaranteed miss + 3 heap allocs. 64MiB cat: 0.318s → 0.122s (−62%), now at the engine copy floor.src/commands/wc.cpp): 7-bit ASCII fast loop mirroring consume_codepoint's ASCII branch, falling back to the UTF-8 decoder on first non-ASCII byte. 64MiB wc: 0.409s → 0.243s (0.64x vs MSYS GNU).Not touched (different layer, documented in PERF-BASELINE.md): cat's ifstream read path and the ~20ms process spawn floor.