Skip to content

Umbrella: the dual-store capture-replay invariant — root cause of #616/#618/#607/#608/#609/#619 and the map for later agents #641

Closed

Description

@caomengxuan666

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

Open, measured, untouched — the perf line, in priority order

Open correctness bugs, split out one concern each

4. Method, so it is applied the same way twice

  1. Attribution before any fix. Measure, isolate the mechanism (a
    key-count or size sweep that changes one variable), then write code.
  2. 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).
  3. GNU bash source is the spec, vendored at third_party/bash/. Cite
    file:function:line. Never a blacklist of observed outputs.
  4. Fix the invariant, not the symptom. Prefer changing the reader's rule
    over patching N writers — a writer list can never be proven complete.
  5. 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.
  6. 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 test without --no-fail-fast aborts at the first failing target.
    Use --no-fail-fast for a full-suite gate, then diff the sets.
  • Never run two cargo invocations at once in this repo. A concurrent
    relink of target/debug/rubash while test processes spawn it produces
    dozens of Text file busy / Permission denied rows — one such run was
    declared void. Run branch and master serially.
  • /tmp is unwritable on this Android host; harnesses must use $PREFIX/tmp.
  • executor_tests is 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.hooksPath is unset in this tree, so the rustfmt pre-commit hook
    does not run. cargo fmt must be run manually before every commit.
  • GitHub git fetch / gh calls intermittently ECONNRESET — retry, and check
    real exit status. gh pr view --json statusCheckRollup can return an empty
    rollup early; verify "name" rows exist before trusting a settle.
  • simpleperf sampling is blocked by security.perf_harden (no adb). Use
    Instant instrumentation instead.
  • /proc/loadavg is unreadable; poll uptime. 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-overridable GNU / 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

  1. caomengxuan666 commented on Oct 16, 2026

    @caomengxuan666
    MemberAuthor

    Status update: #618 perf phase landed as PR #650 (branch perf/issue618-assoc-write, commit 50412ac rebased on 53149ba).

    • Assoc write curve is flat: K=5000 45x faster than master, GNU gap 445x -> 9.9x.
    • Two mechanisms, one PR (second is a dependency of the first): O(1) append + budget compaction; O(n^2) tokenizer root-caused to a whole-rest Vec<char> collect per segment and fixed with arraysub_span_len_str.
    • Read-path lesson for later agents: appending keeps the mirror never-stale, which is what made the 125-site read surface a non-issue. The lazy-cell alternative was rejected on hook analysis, not on perf.
    • Remaining for this family: fixed ~9x pipeline overhead (separate subsystem), 4 cold-path collects (pre-existing), indexed side ([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, 908x @k=5000, same append pattern should apply via its sync family).
  2. caomengxuan666 commented on Oct 16, 2026

    @caomengxuan666
    MemberAuthor

    Status update: #616 perf phase landed as PR #652 (branch perf/issue616-indexed-write, commit 228dcbc on 333973c).

  3. caomengxuan666 commented on Oct 16, 2026

    @caomengxuan666
    MemberAuthor

    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.

  4. caomengxuan666 commented on Oct 16, 2026

    @caomengxuan666
    MemberAuthor

    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.

  5. caomengxuan666 commented on Oct 17, 2026

    @caomengxuan666
    MemberAuthor

    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:

    plane the "N sites" evidence
    variable store (this umbrella) typed cell + mirror string, maintained by capture-replay §2 of this issue: 908× at K=5000
    carrier text 108 files reference markers:: (788 refs); 176 decode-helper call sites in 47 files; 138 manual .replace(markers::…) chains in 31 files; 26 raw replace(CTLESC,"") #729
    subshell context manual snapshot/restore list — taxonomy S6: "非 fork,靠手工快照/恢复清单,新增状态即新泄漏点" #713
    fd table taxonomy S3: "Windows 无真实 fd;内建输出通路 N 条各自打补丁" #699, #726
    process plane merge loses fixes (M5 / S13) — the same shape in the process dimension taxonomy §1

    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:

    • sites touched per new state — adding a field to the execution context should touch one place (a context struct), not a snapshot/restore list. Adding a consumer of expanded text should be impossible-to-forget (a type), not a convention.
    • new instances per family per release — if S1/S3/S6/S9 keep producing instances without new state being added, the invariant is not the root. If a 4-week window produces none once no new state is added, it is.

    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.

  6. added
    performance
    on Oct 17, 2026
  7. arookieofc commented on Oct 19, 2026

    @arookieofc
    Member

    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.

  8. caomengxuan666 commented on Oct 22, 2026

    @caomengxuan666
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

performance

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions