Repository navigation
Description
Parent: #619 (tracking parent; this issue splits out shape 3 of 4).
Shared floor: #607 (per-command dispatch; minor here — mapfile cost is dominated
by input processing, not dispatch).
Problem statement (measured)
Prior: mapfile -t a < lines.txt (100k lines) → 300 ms rubash vs 56 ms bash (5.4×) (pre-#652 store). Re-measured at filing on current master (23badf8, release, 25k lines, min-of-3): 0.05s vs 0.014s (~3.5x) — store half improved by #652 as predicted; remaining gap is this issue's scope (input side);
niu 303 ms (same class). Prior recon attributes the gap to the input-split-encode path:
split_mapfile_input (read → split lines → strip delimiter → encode/store elements), i.e.
per-line allocation + copy + encode churn on the read side. The store half (bulk array
write going through the dual-store/capture-replay diff-sync) was already rewritten by #652 —
so at filing time: re-measure first; whatever ratio remains after #652 is this issue's scope
(input side only), and if the ratio has collapsed to ~1× this issue closes with the numbers.
GNU owner (vendored tree third_party/bash/)
mapfile.def(mapfilebuiltin): reads input, splits on delimiter, assigns elements —
line splitting without per-line re-encoding; the hot loop is read/split/assign.array.c/variables.c::bind_array_variable: element binding into the array structure
(compare against rubash'ssplit_mapfile_input+ bulk-store path; store half post-perf(executor): append indexed overwrite writes instead of re-rendering (#616) #652).builtins/mapfile.def:177-209:zgetlineread loop with per-line
bind_array_element (entry, array_index, line, 0)— line splitting without
per-line re-encoding; the hot loop is read/split/assign:
if (zgetline (fd, &line, &line_length, delim, unbuffered_read) < 0)
...
\tbind_array_element (entry, array_index, line, 0);Fix sketch (ranked; batch re-encode)
- Re-measure post-perf(executor): append indexed overwrite writes instead of re-rendering (#616) #652 (
perf_battery/26_mapfile:mapfile -t a < $benchdata/lines.txt)
and decompose: input-split time vs store time. File the split table in the issue. - Batch re-encode the input side: read the input as bytes once, split on the delimiter
without per-lineStringcopies, strip-tdelimiter in the byte domain, and push lines
into the (post-perf(executor): append indexed overwrite writes instead of re-rendering (#616) #652) bulk store in a single batch — one allocation per line max, no
intermediate re-encoding pass. Ranked first: matches GNU's read/split/assign shape. - Delimiter/callback variants (
-d,-n/-s/-O/-c/-C) keep exact semantics; optimize
the default-t-newline path, leave exotic delimiters on the general path.
Blast radius
split_mapfile_input + mapfile builtin wiring (job_builtins.rs mapfile area) + bulk-store
call site. Affects mapfile/read -a-adjacent bulk reads only. Risk centers on delimiter
stripping (-t), NUL bytes, missing trailing newline, and -O origin offsets — all covered
by existing mapfile probes (probes.sh arr-mapfile, arr-mapfile-O, rd-mapfile-procsub).
NON-goals
- Do NOT touch the store half — already rewritten by perf(executor): append indexed overwrite writes instead of re-rendering (#616) #652; any store-side follow-up files
against perf(executor): append indexed overwrite writes instead of re-rendering (#616) #652, not here. Pending action is re-measure, not re-fix. - Do NOT change
mapfileoption semantics (-d/-n/-s/-O/-c/-C, exit status,
partial-read behavior) — byte-parity with bash required. - Do NOT generalize into a shared "bulk builtin input" framework (read/getopts/COMP_WORDS
stay as-is).
Verification bar (gates)
26_mapfile100k-line workload before/after vs bash (target: approaching parity; close if
post-perf(executor): append indexed overwrite writes instead of re-rendering (#616) #652 already ~1× with table evidence).- Mapfile option matrix:
-t,-O,-d,-n/-s,-c/-Ccallback, NUL/trailing-newline
edges — byte-identical to bash. cargo test --lib578/578;cli_tests= exact [test][platform:linux] 24 cli_tests red on Android unmasked by #613 (fail-fast hid them behind the lib failures): 13 missing bashdb fixture, 6 Windows-hardcoded expectations, 3 host-tool assumptions, 2 to triage #615 ledger 24;executor_testsset
byte-identical to master;probes.sh95/116 unchanged (esp. the three mapfile probes);
cargo fmtclean.
Activity
caomengxuan666 commentedon Oct 16, 2026
Cut up as PR #670 (branch
perf/issue663-mapfile): split decodes once + byte-range split, builtin fast path skips the intermediate index map (no -O/-C). 100k bench 243ms->174ms (4.7x->3.3x vs GNU); matrix 25/26 (1 pre-existing NUL divergence). Gate running.perf(executor): batch mapfile input split + store (#663) (#670)
caomengxuan666 commentedon Oct 16, 2026
Landed as #670 (squash-merged 04ed4bf). 100k bench 243ms->174ms (4.7x->3.3x vs GNU); matrix 25/26 (1 pre-existing NUL divergence); gates identical (niu 49=49). Store-side remainder tracked as follow-ups.
docs: changelog + perf ledger land #661/#662/#663/#664/#609s1/#607ticket
docs: ledger top-up for #663 consumptions (finish_shell, bytes_to_scr…