Skip to content

WIP: perf residual batch — #1955 feeder scans, #2004 assoc length leg, #1994 compgen PATH cache, #1956 verify candidates - #2060

Merged
caomengxuan666 merged 4 commits into
masterfrom
perf/residual-batch-2004-2005-1994-1955-1956
Oct 29, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
perf/residual-batch-2004-2005-1994-1955-1956

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Perf residual cluster (4 fix commits + 1 evidence-only adjudication). All numbers release build, Linux same-machine interleaved sampling (「Linux 同机」), taken against master 16a42d78; full tables + root causes in the cluster REPORT (workspace fix-perf-residual/REPORT.md).

#1955 — grouped-feeder per-pass scans (FIXED, commit 9848fb1)

Feeder re-ran three Θ(accumulated-tokens) scans per appended line inside an open brace group. Instrumentation on master: 504MB of accumulated line handed to the tokenizer, 160M token visits for defs-wrap-8000 -n; attribution: resume-gate rposition 14.1s, heredoc_delimiters 9.0s, line_posix_mode_change 3.2s (debug-run totals). All three are now resumable/watermarked in the checkpoint discipline the param/comsub scans already use; delimiter structs still computed once on the commit path.

  • defs-wrap-8000 -n (paired same-window, min-of-5): 3.248s → 0.533s; growth per doubling ≈×4.0 → ≈×2–3 (near-linear).
  • 8/8 GNU differential shapes byte-identical (incl. split set -o lines, heredoc operator straddle, posix mid-unit deferral).

#2004 — combined-table miss (PARTLY OVERTURNED + length leg FIXED, commit b5bcf59)

Re-measurement overturns the filed plain-miss magnitude on current master: the F3 fix (#1919) already settled plain ${m[key]} (miss@10000 = 18.3µs vs GNU 13.4µs, flat). The live residual was the LENGTH leg: ${#m[key]} re-derived from serialized storage per call, hit AND miss (miss@10000 1115µs, growth ×5–11). New assoc_element_value_settled answers by-key reads under the typed fetch's own admission/freshness gate; both length legs (direct + nameref-cell) consult it after their single subscript evaluation; the empty-key error (subst.c:7545-7552) still fires first.

  • After (final binary): len miss growth ×10.67 → ×1.08 (1653µs → 125µs under load), len hit ×11.08 → ×1.34.
  • 4 new behavior pins (hit/miss/empty-hit, subscript evaluated once, nameref leg, empty-key error), GNU-verified.

#2005 — while-read 418µs/line (OVERTURNED as filed — NO code change)

On current master the shape decomposes to the general while+arith floor tax (already tracked by #682), not a read/procsub defect: while-read from procsub/file/pipe = 172/139/129µs/line under load vs an arith-only loop at 76µs/iter and read adding only ~21µs/iter; cat-drain of the same procsub = 1.3µs/line (the #1952 streaming fix holds). The filed 418µs/68x was measured on a268db2, pre-#1952-merge. Full evidence table in the cluster report for adjudication. (Adjacent: #1951's 0.29ms/line procsub claim is the same stale shape.)

#1994 — compspec PATH walk (FIXED, commit e8b4f07)

path_command_completion_candidates re-walked + stat'ed the whole PATH universe per evaluation. The raw walk (duplicates preserved, #1089) is now memoized process-wide under command_lookup_fingerprint (PATH/PWD/PATHEXT + path-translation keys); a PATH bind or cd re-walks. Accepted staleness mirrors the niubash host-side cache.

  • Fat PATH (~2900 fakes + system, 3137 candidates, same window): 110.6ms → 13.6ms per compgen -c (8.1×; GNU 277.6ms). Candidate sets identical.
  • Pin: stability across calls, dup/exec/symlink discipline, refresh on PATH change.

#1956 — debug-only verify walks whole variable table (FIXED, commit 236664a)

The boundary verifier iterated all variables per command. It now visits only stale ∪ cell-candidates (a new debug-only registry in VariableStore, fed by every cell-creating/replacing/destroying mutation; get_mut registers conservatively); per-name treatment unchanged, forced fuzz variant still walks everything. Release builds compile the registry out.

  • Debug, assign-wrap 1000/2000/4000/8000: 636/4147/9430/39094ms → 276/1858/4796/12050ms. Note: the shape keeps a second, release-visible superlinear term outside the verifier (release assign-wrap-8000 = 1.41s) — flagged for a separate look, not this issue's mechanism.

Gates (final tree vs master baseline, same discipline)

  • lib: 925/1/3 both; failure name set identical (ownership_unary_operators_check_existing_file).
  • regression: baseline 188/7/1; final 186/9/1 — the +2 adjudicated: golden_nvm_load is a best-of-5 timing gate that failed at load ~13.6 (10.20s vs 9.09s budget) and PASSES on re-run; issue1776_time_children_cpu fails identically on the pristine baseline tree (same assertion at regression.rs:3396).
  • diffcorpus 306: 306/306 both (one bi08 timing-flake on the first final run, 306/306 on re-run).
  • cargo check --lib --bins with -D warnings: clean. Per-file rustfmt applied; CR count 0.

Refs #2004, #2005, #1994, #1955, #1956 — closure adjudication left to the main session (#2005 is evidence-only; #2004's plain-path half was already fixed by #1919).

caomengxuan666 and others added 4 commits October 29, 2026 02:24
The grouped-reader feeder re-ran three whole-token-list scans on every
appended physical line while a brace group stayed open, so a group of N
one-line function definitions cost Theta(N^2) token visits (measured on
master 16a42d7, Linux same-machine: defs-wrap -n grew x4.0 per doubling,
8000 defs = 2.77s vs GNU 0.026s; per-pass instrumentation counted 504MB
of accumulated line handed to the tokenizer and 160M token visits).

GNU reads a script exactly once (parse.y:3557 read_token streams); the
three scans now keep resumable state over the append-only token list,
following the checkpoint discipline the param/comsub/quotes scans
already use:

- resume gate: the innermost bare `{` of the checkpoint list is the
  fold-maintained mirror (fold_pass_tokens tracks the last bare `{`
  over the delta on tail-resumed passes and rebuilds it on refolds),
  snapshotted next to the boundary checkpoint when it is stored. The
  per-line rposition over all checkpoint tokens is gone.
- heredoc presence: a windows(2) watermark (prefix answer + straddle
  pair + delta pairs) answers the join decision; the delimiter structs
  are still computed by one full heredoc_delimiters call on the commit
  path, against the final source text their contexts read.
- `set -o posix` flip scan: LinePosixScan folds the appended delta,
  re-probing a `set` word whose argument list was cut off by the
  previous pass's end (Undecided probe outcome), so the running result
  equals the from-scratch scan on every pass.

After (same load window, min-of-5, Linux): defs-wrap-8000 -n 3.25s ->
0.53s, growth per doubling ~x2-3 (near-linear); 8/8 GNU differential
shapes byte-identical (defs exec, heredocs in groups incl. split
operator, `}` in strings/comments, split `set -o` lines, posix
mid-unit deferral, nested case/procsub/dparen).

Co-Authored-By: Muse Spark <[email protected]>
…h#2004)

Re-measurement on master 16a42d7 (Linux same-machine, interleaved)
overturned the filed plain-miss magnitude: the F3 fix (rubash#1919)
already settled plain ${m[key]} reads — miss at n=10000 is 18.3us vs
GNU 13.4us (1.36x), flat in n. The live residual is the LENGTH leg:
${#m[key]} re-derived the element from the serialized storage on every
call (whole-storage clone + content-hash + linear scan), hit AND miss:
at n=10000, 479us (hit) / 1115us (miss) per call vs GNU 16us / 4us,
growing x5-11 per 10x of table size.

assoc_element_value_settled answers by-key reads for callers that
already hold the evaluated key, under the typed fetch's own admission
(nameref resolved, assoc mark on the storage name, rubash#1510
freshness gate, structured assoc cell present); the cell — a complete
mirror of the render (rubash#616 Phase 1a) — then settles hit and miss
authoritatively. Both length legs (direct, and the nameref-cell leg)
consult it after their single subscript evaluation and after the
empty-key `bad array subscript` error (subst.c:7545-7552); unsettled
reads keep the storage leg unchanged. GNU: assoc.c assoc_reference is
one hash lookup, hit or miss.

Pins: 4 new behavior pins in perf_assoc_element_miss_regressions.rs
(length hit/miss/empty-hit, subscript evaluated once on hit and miss,
nameref leg + multibyte length, empty-key error), expectations
verified byte-for-byte against GNU bash 5.3.20.

Co-Authored-By: Muse Spark <[email protected]>
…nt (rubash#1994)

path_command_completion_candidates re-walked every PATH directory
and stat'ed every entry on every compspec evaluation / compgen -c.
Measured on master 16a42d7 (Linux same-machine, fat PATH of ~2900
fake executables + system PATH, 3247 unique candidates): 95ms per
in-shell compgen -c call, paid again on each of 200 consecutive
calls (GNU re-walks too and pays 302ms — rubash keeps the lead and
drops the repeat cost).

The raw walk result (duplicates across directories preserved,
rubash#1089; callers merge/sort/dedup) is now cached process-wide
under command_lookup_fingerprint — the executor command-lookup
cache's key (PATH/PWD/PATHEXT + every env key path translation
consults), now pub(crate) for this reuse. A PATH bind or cd moves
the fingerprint and the next evaluation re-walks. Accepted
staleness, mirroring the niubash host-side cache: filesystem-only
changes under an unchanged fingerprint are observed at the next
fingerprint change.

Pin: issue1994_compgen_path_cache_regressions.rs — repeated calls
identical, dup/exec/symlink discipline, refresh on PATH change;
expectations verified against GNU bash 5.3.20.

Co-Authored-By: Muse Spark <[email protected]>
…ash#1956)

The debug-only command-boundary verifier iterated the whole variable
store and paid a per-name freshness check for every variable — a
group of N scalar assignments cost Theta(N^2) (filed: 8000 distinct
assignments 19.1s in a debug build; reproduced on master 16a42d7,
Linux same-machine: 39.1s under load).

The non-forced pass now visits only stale ∪ cell-candidates: a celled
name that is not fresh is either stale (every mirror-epoch bump is
paired with the stale mark) or untracked, and every untracked celled
name sits in the store's new cell registry — each VariableStore
mutation that can create/replace/destroy a cell registers it
(array-directed setters unconditionally, wholesale `set` by outcome,
`get_mut` conservatively), and the verifier drops names it observes
cell-less. Per-name treatment (freshness skip, mirror-absent skip,
full proof, track on proof) is the old loop's, factored into
typed_cell_coherent; the forced fuzz variant still walks the whole
store. The registry is #[cfg(debug_assertions)] state, like the
verifier itself — release builds pay nothing.

Debug, same machine, min-of-3: assign-wrap 1000/2000/4000/8000 =
636/4147/9430/39094ms -> 276/1858/4796/12050ms. The shape keeps a
second, release-visible superlinear term outside the verifier
(assign-wrap-8000 release: 1.41s) — separate mechanism, flagged in
the cluster report. typed_cell_coherence_fuzz + issue1719 sync
regressions green.

Co-Authored-By: Muse Spark <[email protected]>
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 29, 2026 05:47
@caomengxuan666
caomengxuan666 merged commit 88496e5 into master Oct 29, 2026
11 checks passed
@caomengxuan666
caomengxuan666 deleted the perf/residual-batch-2004-2005-1994-1955-1956 branch October 30, 2026 01:42
caomengxuan666 added a commit that referenced this pull request Oct 30, 2026
- PR #2060 has merged; drop the 'still draft, numbers pending' wording
- page-level platform caliber: all figures are same-machine
  comparisons and say nothing about Windows magnitudes; the
  2026-10-28 and residual rounds are explicitly this Linux VM
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