Skip to content

perf(executor): skip the mapfile whole-input encode roundtrip (#680) - #688

Merged
caomengxuan666 merged 1 commit into
masterfrom
perf/issue680-mapfile-store2
Oct 17, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
perf/issue680-mapfile-store2

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

perf(executor): skip the mapfile whole-input encode roundtrip (#680)

What

Second slice of the mapfile store-side residual: split_mapfile_input
ran the whole input through shell_text_to_raw_bytes and then
re-encoded every segment via bytes_to_shell_text, even for plain
ASCII input where both directions are the identity.

Fix

Admission predicate (single byte pass): ASCII-only input, no carrier
bytes (0x0c/0x11/0x13/0x14..=0x1f — the only bytes that make
bytes_to_shell_text differ from its input), ASCII non-NUL
delimiter. Admitted inputs split the text directly (one alloc per
segment); anything else keeps the decode path (rubash#117). NUL-delim
stays on the decode path by contract.

GNU: builtins/mapfile.def:177-209 (split raw bytes, no re-encode).

Measured (release, same-tree fresh binaries)

Small but sound; same bar as #671/#679.

Verification

  • Contract issue680_mapfile_encoded_split_regressions (4 tests:
    plain, custom delim ±-t, NUL-delim decode path, carrier-byte
    fallthrough pinned against GNU output).
  • mapfile 24/24; mapfile_diff.sh 30/30.
  • Full serial failure-set gate vs master: per-target results match
    except the new regression file itself (4/4). Test-level 3 NEW, all in
    the known-nondeterministic part_080 coproc family (all pass in
    isolation on branch). No regression.
  • niubash product A/B (niubash pinned 6295367, only rubash [patch]
    switched): failure sets byte-identical (8=8). Note: the product
    failure set shrank 49→8 since the [perf][P2] Split #619 (2/4): case per-arm pattern re-expansion constant (~1.27 vs 0.51µs/arm) #662 era — the engine campaign
    fixed 41 niubash product tests as a side effect (the 8 are a strict
    subset of the old 49).

split_mapfile_input encoded the whole input to raw bytes then
re-encoded every segment, even for ASCII input where both directions
are identity. Admission: ASCII-only, no carrier bytes, ASCII non-NUL
delim; admitted inputs split directly (one alloc/segment).

seq1M 0.686s -> 0.645s (-6%). 4 contract tests; mapfile 24/24.

GNU: builtins/mapfile.def:177-209.
@caomengxuan666
caomengxuan666 merged commit 31d1f0f into master Oct 17, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the perf/issue680-mapfile-store2 branch October 17, 2026 00:42
caomengxuan666 added a commit that referenced this pull request Oct 18, 2026
…itative carrier set (#680 followup)

Fuses the two #680 slice-2 variants that were floating apart: master's
merged fast path (31d1f0f, #688) required the WHOLE input to be ASCII, so
any multi-byte payload (CJK, accented text) fell back to the whole-input
decode + per-segment encode roundtrip, while rescue/stash-perf-680 (a
stash rescue of the same slice) already rode UTF-8 but gated on a
hand-rolled C0 whitelist that over-excluded 0x0B/0x0E/0x0F/0x10/0x12 —
bytes outside the authoritative carrier set that encode to themselves —
and coupled the gate to markers.rs by hand.

The fused gate is `is_assignment_carrier_byte` (lexer/ansi.rs — the
authoritative set {0x0c, CTLESC 0x11, 0x13, 0x14..=0x1f} shared with
bytes_to_assignment_shell_text) plus the 0xEE lead of the U+E000..U+EFFF
registry-marker zone, on both the delimiter and every input byte. A
future carrier registration automatically tightens the gate instead of
relying on a synced copy. Correctness of the UTF-8 coverage rests on the
Rust String invariant (input is always valid UTF-8, so an ASCII
delimiter can never cut a multi-byte sequence and every segment is
either ASCII or carries complete sequences that re-encode to
themselves); non-carrier C0 bytes (tab/LF/CR/VT) and DEL encode to
themselves and stay on the fast path; NUL keeps the decode path by
contract (delim != 0, rubash#117).

Oracle-verified against the locally built bash-5.3.0(1)-release:
mapfile -t with UTF-8 payloads, carrier bytes (0x0c/0x11) and a
registry-marker stream all render byte-identically to GNU, including
the -d delimiter variants. Two new pins in
issue680_mapfile_quote_fastpath_regressions.rs cover the UTF-8 ride and
the carrier/marker gate; the issue680 pair, marker_leak_golden and the
lib suite stay green. rescue/stash-perf-680-mapfile-input-side is
superseded by this and can be deleted.
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