Skip to content

[perf][P2] Split #619 (3/4): mapfile input split + encode path (store half already fixed by #652) #663

Closed

Description

@caomengxuan666

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 (mapfile builtin): 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's split_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: zgetline read 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)

  1. 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.
  2. Batch re-encode the input side: read the input as bytes once, split on the delimiter
    without per-line String copies, strip -t delimiter 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.
  3. 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

Verification bar (gates)

Activity

  1. caomengxuan666 commented on Oct 16, 2026

    @caomengxuan666
    MemberAuthor

    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.

  2. caomengxuan666 commented on Oct 16, 2026

    @caomengxuan666
    MemberAuthor

    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.

  3. added a commit that references this issue on Oct 16, 2026
  4. added
    performance
    P2-medium
    on Oct 17, 2026
  5. added a commit that references this issue on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2-mediumperformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions