Skip to content

perf(executor): batch mapfile input split + store (#663) - #670

Merged
caomengxuan666 merged 1 commit into
masterfrom
perf/issue663-mapfile
Oct 16, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
perf/issue663-mapfile

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

perf(executor): batch mapfile input split + store (#663)

What

mapfile -t a < lines.txt (100k lines): 243ms vs GNU 52ms (~4.7x).
Instrumentation showed split = 18ms, store = 141ms of the gap — the
caller's intermediate BTreeMap build plus its drop dominated, not just
split_mapfile_input (~10%).

Fix

  • split_mapfile_input: decode once, split raw bytes as ranges (no
    per-byte push buffer), strip -t in the byte domain, encode each
    segment exactly once. Capped reserve.
  • mapfile_builtin: fast path when origin.is_none() && callback.is_none() — batch pushes straight into the dense bulk store
    (replace_typed_indexed_array + store_indexed_array), skipping the
    intermediate index map. All attribute checks (readonly/nameref/
    identifier) and the epilogue stay upstream/identical; -O/-C paths
    untouched.

GNU owners: builtins/mapfile.def:177-209 zgetline loop +
bind_array_element.

Measured (release, 3 mapfiles/process, per-call)

input before after GNU
100k lines 589KB 243ms 174ms 52ms (4.7x→3.3x, 1.40x)
100k×1B 187ms 169ms 50ms
100k×100B 680ms 555ms 152ms

Remaining ~3.3x is store-side (per-element quote allocs, typed-cell
double-keep, whole-input encode→decode roundtrip) — each its own
follow-up PR.

Verification

  • executor_tests mapfile 24 passed; readarray 11 passed;
    issue324 5/6 (the 1 failure writes /tmp, unwritable here —
    fails identically on base).
  • Byte-parity matrix (26 probes: -t/-O/-d/-n/-s/-c/-C, NUL, missing
    newline, CRLF, \xff, UTF-8, procsub, pipe, callbacks): 25/26 vs GNU;
    the 1 divergence (NUL-in-data truncation) is pre-existing and
    byte-identical between old and new split.
  • Full serial failure-set gate vs master: target sets identical
    (NEW=0/DISAPPEARED=0). Test-level 4 NEWs all pass in isolation on
    branch (3 part_080 coproc = known flake family;
    pipeline_allows_newline_after_operator green on both legs) —
    no regression.
  • niubash product A/B (niubash pinned 6295367, only rubash [patch]
    switched): failure sets byte-identical (49=49).

mapfile -t a < 100k lines: 243ms vs GNU 52ms (~4.7x); split was only
~10% (18ms), the caller-side intermediate BTreeMap build+drop was
141ms.

split_mapfile_input decodes once, splits raw bytes as ranges, strips
-t in the byte domain, encodes each segment once. The builtin fast
path (no -O/-C) pushes the batch straight into the dense bulk store,
skipping the intermediate index map. Attr checks and epilogue
unchanged; -O/-C paths untouched.

100k bench 243ms -> 174ms (4.7x -> 3.3x vs GNU). Matrix 25/26 vs GNU
(1 pre-existing NUL divergence, identical old/new).

GNU: builtins/mapfile.def:177-209 zgetline + bind_array_element.
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