Repository navigation
Description
Umbrella: the dual-store capture-replay invariant — what is fixed, what is measured, what is next
This is a map, not a work item. It exists so a later agent does not have to
re-derive the architecture, re-run the attribution, or re-discover which
measurements are trustworthy. Each row links to its own issue; nothing here is
a new concern — one concern per PR still applies.
1. The root cause, in one paragraph
rubash keeps every variable in two places: a typed cell (Rust-side
IndexedArray / AssociativeArray / scalar) and a mirror string in
env_vars that is what a child process and most readers actually see. The
mirror is maintained by capture-replay: after a write, the whole variable is
re-rendered into its string form. Therefore one write costs O(elements that
already exist), not O(1). GNU bash does not pay this — array_insert
(third_party/bash/array.c) and assoc_insert (third_party/bash/assoc.c)
are O(1) amortized per element and the VAR= environment string is only
materialized when a child is actually forked.
This single structural property is the cause of every performance issue
below, and of several correctness bugs where the two stores disagree.
2. Attribution, already measured — do not re-derive this
Measured on 12da0b5, release build, min-of-3, shell order rotated per round.
Local GNU bash is 5.3.20 while the repository oracle is WSL 5.3.0; the
rules cited in each issue come from the vendored third_party/bash/ C source,
never from a version's observed output.
Key-count sweep — the decisive evidence. Writes fixed at 20000, only the key
count varies. Per-write cost tracking key count is the O(keys)-per-write
signature:
| keys K | assoc rubash/GNU | indexed rubash/GNU |
|---|---|---|
| 10 | 1.1x | 5.3x |
| 100 | 1.9x | 21.7x |
| 1000 | 22.0x | 211.1x |
| 5000 | 223.0x | 907.8x (98.947s vs 0.109s) |
The curve is still linear in K at the top end, which proves the structural
re-render is still present despite phases 1a/1b/1c having landed. Those
phases added memos and a sync family at the edges; they did not remove the
per-write full re-render.
3. Status board
Landed
- [perf][P1] Array mutation is O(n²) and ${#arr[@]} is O(n): a[i]= / a+=() 39-666× slower, length query ~230× — dual-store capture-replay replays per element write #616 phases 1a / 1b / 1c (via perf(array): O(1) ${#a[@]} via the typed indexed cell, zero behaviour change (#616 Phase 1a) #627, for-list word with a double quote leaks the DATA_DQUOTE carrier into compound array append #629, [compat] Out-of-range negative subscript in a compound assignment a+=( [-N]=v ) is silently dropped — GNU reports "bad array subscript" and aborts the assignment #631, fix(executor): report a bad array subscript in a compound assignment (#631) #634 — master at
12da0b5): bad-subscript reporting, compound-assignment subscript errors,
quote regressions. Zero product regression verified on niubash by
failure-signature set diff across three runs. - set -u: the scalar form of an array/assoc is bound by element 0, not by "any element" #638 (PR fix(parameter_errors): judge the scalar form bound by element 0 (#638) #640):
set -uscalar form of an array/assoc is bound by
element/key0, not by "any element" (subst.c:7787-7790,
array.c:657,assoc.c:120,subst.c:10162-10169→error.c:448).
Fixed at the reader (the mirror decides boundness via the same helpers
the value read uses), not by wiring drops into the ~12 writers.
Open, measured, untouched — the perf line, in priority order
- [perf][P1] Array mutation is O(n²) and ${#arr[@]} is O(n): a[i]= / a+=() 39-666× slower, length query ~230× — dual-store capture-replay replays per element write #616 next phase — indexed store, 908x at K=5000. The sharpest
instance of the root cause. - [perf][P1] Associative-array write m[$k]=v is 16.7× slower (73µs/op vs 4.3µs, 100 keys) — same store/diff-sync family as #616 #618 — assoc write, 223x at K=5000 / 18.3x at 100 keys. Attribution
complete; no perf code written yet. The fix must remove the
O(keys)-per-write re-render atassignment_helpers.rs:345 format_assoc_storage
and its indexed equivalent. - [perf][P1] Scalar assignment path 2.72x slower: unconditional xtrace-only memo insert, dual BTreeMap+HashMap stores with replay log, nameref pre-allocation #609 — scalar assignment 2.72x (xtrace-only memo insert, dual
BTreeMap+HashMap stores, nameref pre-allocation). - [perf][P1] Parameter expansion 2.6-7.3x slower than GNU: ${x^^} heap-allocates and glob-matches every character (GNU transforms directly when pat==NULL), plus per-call pattern re-derivation in // and #/% #608 — parameter expansion 2.6–7.3x (
${x^^}heap-allocates and
glob-matches per character; GNU transforms directly whenpat == NULL). - [perf][P1] Arithmetic-for / loop execution 2.37x slower than GNU bash: per-eval state ticket, lvalue+read+write allocations, CommandNode rebuild, per-command probes #607 — arithmetic-for / loop 2.37x.
- [perf][P2] Control-flow eval overhead: [[ ]] 5.3×, case 5.6×, mapfile 5.4×, glob 3.5×, source 2.8× — conditional constructs re-tokenize per exec (29-workload battery) #619 — control-flow eval 3.5–5.6x (conditional constructs re-tokenize
per exec).
Open correctness bugs, split out one concern each
- declare -a a=( [-2]=q ) / local -a a=( [-2]=q ) still drop an out-of-range negative subscript (builtin route of #631) #635 —
declare -a a=( [-2]=q )builtin route still drops an
out-of-range negative subscript (the [compat] Out-of-range negative subscript in a compound assignment a+=( [-N]=v ) is silently dropped — GNU reports "bad array subscript" and aborts the assignment #631 leftover). - compound a+=( [@]=q ) reports an arithmetic error instead of "cannot assign to non-numeric index" #636 — compound
a+=( [@]=q )reports an arithmetic error instead of
"cannot assign to non-numeric index". - eval does not contain the assignment DISCARD jump (eval 'a[-2]=q' ends the whole script) #637 —
evaldoes not contain the assignment DISCARD jump
(eval 'a[-2]=q'terminates the whole script). - set -u: an arithmetic array subscript is expanded without the nounset check #639 — arithmetic subscripts bypass nounset entirely
(set -u; a[k]=vsilently succeeds; GNU fails during the assignment).
This is the one known remaining difference in the set -u: the scalar form of an array/assoc is bound by element 0, not by "any element" #638 differential
battery (39/40 byte-identical). - [compat] Differential probe battery: getopts stale-OPTIND breaks the shift $((OPTIND-1)) idiom; multi-negative-subscript expansions spam stderr; history dumps the user file under -c #614 — getopts stale
OPTIND; multi-negative-subscript expansions spam
stderr;history -cdumps the user file. - [compat][#615] Unquoted indexed compound expansion of whitespace-padded values creates empty elements (scalar + assoc) #621 — unquoted indexed compound expansion of whitespace-padded values
creates empty elements (scalar + assoc).
4. Method, so it is applied the same way twice
- Attribution before any fix. Measure, isolate the mechanism (a
key-count or size sweep that changes one variable), then write code. - One concern per PR. When a survey surfaces two defects, file the second
as its own issue (set -u: the scalar form of an array/assoc is bound by element 0, not by "any element" #638 was split out of [perf][P1] Associative-array write m[$k]=v is 16.7× slower (73µs/op vs 4.3µs, 100 keys) — same store/diff-sync family as #616 #618 this way; set -u: an arithmetic array subscript is expanded without the nounset check #639 likewise). - GNU bash source is the spec, vendored at
third_party/bash/. Cite
file:function:line. Never a blacklist of observed outputs. - Fix the invariant, not the symptom. Prefer changing the reader's rule
over patching N writers — a writer list can never be proven complete. - Ratchet, never counts. Compare failing-test sets, serially
(--test-threads=1), branch vs master in the same tree. A count hides a fix
sitting next to a break. - Never publish a tainted number. Baseline master in the same tree; never
measure with a stale or instrumented binary; if a run races (see §5), declare
it void and re-run rather than explaining it away.
5. Host pitfalls, learned the hard way
cargo testwithout--no-fail-fastaborts at the first failing target.
Use--no-fail-fastfor a full-suite gate, then diff the sets.- Never run two
cargoinvocations at once in this repo. A concurrent
relink oftarget/debug/rubashwhile test processes spawn it produces
dozens ofText file busy/Permission deniedrows — one such run was
declared void. Run branch and master serially. /tmpis unwritable on this Android host; harnesses must use$PREFIX/tmp.executor_testsis red at scale on this host (1172 failures on both
master and branch). That is environment-bound. The instrument is the
failure-set diff, not the raw count.command_chaining::part_080(coproc family) is nondeterministic under load
and passes in isolation on both sides. Treat its churn as noise.core.hooksPathis unset in this tree, so the rustfmt pre-commit hook
does not run.cargo fmtmust be run manually before every commit.- GitHub
git fetch/ghcalls intermittently ECONNRESET — retry, and check
real exit status.gh pr view --json statusCheckRollupcan return an empty
rollup early; verify"name"rows exist before trusting a settle. - simpleperf sampling is blocked by
security.perf_harden(no adb). Use
Instantinstrumentation instead. /proc/loadavgis unreadable; polluptime. The host is never idle
(load ~4–8 on 6 cores), hence order-rotated min-of-N for every measurement.
6. Where the durable material lives
docs/perf-issue-616-array-store.md— the design write-up, updated per phase.~/bench_niu/attrib_618.sh— the assoc/indexed correctness+cost harness
(env-overridableGNU/RUB/N/ROUNDS).~/bench_niu/ratchet.sh— serial failure-set ratchet.~/bench_niu/diff_full.sh— full-suite log → per-target failing-test sets →
NEW / DISAPPEARED diff.
Activity
caomengxuan666 commentedon Oct 16, 2026
Status update: #618 perf phase landed as PR #650 (branch
perf/issue618-assoc-write, commit50412acrebased on53149ba).Vec<char>collect per segment and fixed witharraysub_span_len_str.caomengxuan666 commentedon Oct 16, 2026
Status update: #616 perf phase landed as PR #652 (branch
perf/issue616-indexed-write, commit228dcbcon333973c).caomengxuan666 commentedon Oct 16, 2026
Status update: compat batch landed (#636, #637, #639, #635, #651, #621 — issues closed, #614 verified-closed); #619 split into #661-664 with re-measured numbers (if/case 2.7x/2.6x, mapfile ~3.5x, glob 4.1x); perf queue is #607 -> #608/#609 -> #661-664. Method note for later agents: background-agent completion notices interleave into live terminal output — capture key measurements to files before reading.
docs: dual-store capture-replay invariant umbrella (#641)
caomengxuan666 commentedon Oct 16, 2026
Umbrella content landed as docs/dual-store-invariant.md: invariant stated once, per-writer owner list (file:function), residual risks, and the perf-slice map (#616/#618/#607/#608/#609/#619 splits with PR numbers). Audit note: ~185 insert sites, completeness never proven — prefer reader-side fixes per #638.
caomengxuan666 commentedon Oct 17, 2026
Adding to this map rather than opening a parallel one — that is what its stated purpose asks for. Three things it does not yet cover, all from an external differential pass this week (Windows x64, GNU bash 5.3.0 as oracle).
1. This may be one instance of a general invariant, not one invariant
§1 names the dual-store as the root of the perf line. An external audit of the carrier protocol suggests the same shape recurs in three more planes:
markers::(788 refs); 176 decode-helper call sites in 47 files; 138 manual.replace(markers::…)chains in 31 files; 26 rawreplace(CTLESC,"")If that holds, the fix for the perf line and the fix for the bug families are the same kind of fix — remove the manual mirroring — and they can share one gate. If it does not hold, this table is the cheapest way to falsify it.
2. A leading indicator, so the map is falsifiable
§4 already has the measurement discipline; what the map lacks is a number that says whether the refactor is working. Two candidates, both cheap:
Same spirit as §4 rule 5 ("ratchet, never counts"), applied to the refactor rather than to the suites.
3. The axis this map does not cover: the interactive/login surface
Everything in the external pass above is non-interactive (
-c, script files, stdin). niubash is now being used as a login shell under tmux — the opposite shape: terminal-attached, long-lived, Ctrl-C, paste, prompt, history. The recent P1s in the tracker sit exactly there (#341 paste swallowing line starts, #373 DSR fallback, #284/#291 paste heuristic, #287 typeahead, #355 history recall, #245/#286 stdout-close). That surface probably wants its own row and its own gate (the interactive journey harness), separate from the semantic ledger this map tracks.Flagging the additions only — not proposing to re-scope anyone else's work item.
arookieofc commentedon Oct 19, 2026
Status check 2026-10-20: all items on this map's board now read CLOSED (verified just now via gh, one by one). Perf line: #616, #618, #607, #608, #609, #619. Correctness line: #614, #621, #635, #636, #637, #639. The board in the issue body is stale but not editable from here, so recording it in a comment instead of a PR: nothing on the board is still open. Whether this map itself should stay open as an index or be closed is the author's call.
caomengxuan666 commentedon Oct 22, 2026
Umbrella completed — closing with the final map (verified against origin/master 323a3e0, all items CLOSED/COMPLETED):
Note §3's Open list and §2's old #619 attribution (per-exec re-lexing, later self-corrected in #619 comments to dispatch residue) are stale as of close — future perf attribution should follow each issue's latest comments, not this umbrella's body.