Skip to content

perf(expand): walker entry-chain trim (pending-diag borrow, body buffer reuse, scalar memo skip) - #973

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/walker-entry-chain-2
Oct 21, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/walker-entry-chain-2

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Follow-up to #965. gdb shows per-${} entry tax spread across fragment walkers, no single leaf >15%. Cut: PENDING_DIAGNOSTIC_WORD borrow+Cell (no String per fragment), collect_braced_parameter_body_into with buffer reuse, whole-word routed span skips re-scan, pooled synthetic ${name}, skip AEPV memo for bracket-less scalar reads, shell_option_default match instead of linear scan. All whitelist/fall-through. Tests: lib 676 + cli green (dirty-banner fail only) + fuzz. Param group another ~5-10% (upper 1.62->1.46, bare-dollar 1.38->1.19).

…pool, funsub/memo/shared gates)

gdb sampling (release, 60 samples/load, while-true steady loop) shows the
residual after #965 is a diffuse per-${}/per-word entry tax, not one
operator: replace-all has expand_braced_parameter_fragment_in_word 16/60,
expand_quoted_parameter_word_mut 14/60, expand_embedded_parameters 17/60
with no single leaf >15%; command-word loads have expand_command_words
30/60 with shell_option_enabled as the top leaf (6/60) and
SubXpassFrame::new on the leaf path. GNU subst.c:11229
expand_word_internal runs parameter_brace_expand inline on the same
buffer with no re-entry, no per-fragment String, and no per-word memo
stack — the intermediates are port artifacts.

Six entry/shared-layer cuts, all whitelists/dedup that fall through to
the real path on semantic doubt (rubash#117); no operator implementation
and no #967 command_prepare area touched:

- expand_word: PENDING_DIAGNOSTIC_WORD stores a borrowed (ptr,len) with
  Cell instead of an owned String per walked ${} fragment; the value is
  materialized only on the bad-substitution path that almost never fires.
- command_subst_helpers: collect_braced_parameter_body_into appends into
  a caller buffer so hot walkers collect straight into a pooled synthetic
  ${...} word instead of staging a per-fragment String (GNU
  subst.c:9777 scans the body inline).
- parameter_words: depth pool of synthetic ${name} words for
  expand_braced_parameter_fragment_in_word; routed
  expand_quoted_parameter_word_mut_routed threads the already-proved
  whole-word span so the fragment re-entry skips its own brace scan and
  its top-level funsub scan (whitelist: '=' / funsub-introducer / span
  shapes keep the full pipeline).
- embedded_parameters: the &self walker collects into the same pooled
  synthetic word (byte-identical content).
- arrays/executor: array_element_parameter_value skips the AEPV memo for
  names without '[' (a scalar read can never be a subscript side effect).
- builtins/set: shell_option_default matches on the name instead of a
  linear SHELL_OPTIONS scan (per-command/per-expansion probe, absent key
  falls through here every time).

Measured (release, bench-param.sh best-of-3 vs GNU bash 5.3.20 aarch64):
before -> after: default-minus 1.83->1.73, default-minus-set 2.08->1.93,
length 1.99->1.97, substr-off-len 1.88->1.80, substr-neg 1.79->1.72,
replace-first 1.91->1.72, upper-all 1.62->1.46, lower-all 1.58->1.49,
prefix-trim 1.68->1.58, suffix-trim 1.75->1.67, indirect 1.63->1.62,
bare-brace 1.32->1.22, bare-dollar 1.38->1.19 (control moves with the
per-command gate; reruns vary +/-0.1 on this device).

Verified: cargo fmt clean; cargo test --lib 676 green; cli_tests
468/469 (sole failure is the version-banner dirty-stamp on a modified
tree, same as base); typed_cell_coherence_fuzz 2/2.
@caomengxuan666
caomengxuan666 merged commit 2dc64df into master Oct 21, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/walker-entry-chain-2 branch October 21, 2026 08:45
caomengxuan666 added a commit that referenced this pull request Oct 21, 2026
…est platform status, current architecture (#982)

* docs(readme): overhaul — Performance section with pinned numbers, honest platform status, current architecture

- New Performance section, every number pinned to its measuring issue/PR:
  - Android-matrix interpreter triage closed with numbers (#607/#608/#609
    -> #665/#671/#679, #666, #672/#678; net ~1.06x GNU scalar assign)
  - array store O(n^2)->O(1) amortized (#618/#616: assoc 445x->9.9x,
    indexed 736x->3.8x vs GNU at 5000 keys; docs/performance.md ledger)
  - literal fast-path wave with measured deltas: #967 (177->155 ms),
    #966 (1.41x->1.10x), #974 (~11%), #959 (3.65x->3.16x), #958 (-10%),
    #956/#973/#954 family
  - export/unset economics: #916 measured costs stated, write lane landed
    (#917/#918/#920, #943 correctness rework), issue open on residual
  - Windows process economics: #913 one hidden console per session
    (~22 ms/spawn -> <=1 per session; tests/console_window_gate.rs),
    #884 tput inline arm (1165 ms -> 47 ms, 269-row oracle matrix),
    WinuxCmd#1269 twin (~17 ms -> ~0.4 ms in-process), #800 face B open
- Platform status made verifiable: Linux CI lanes + upstream-corpus replay
  job named; 19/24 Linux pass dated and cited (#500) instead of 'and
  climbing'; macOS now runs lib tests in CI, not just compiles
- Architecture tree updated to the real src/ layout (bin/expand/fd/jobs/
  shell added); builtin count 40+ -> 62 engine builtins per the
  test-guarded docs/builtins.md + hidden fast-path builtins
- Testing section: regression suite, console gate, corpus replay commands
- Compatibility baseline line updated to vendored Bash-5.3 patch 20
  (#957) with local+WSL 5.3.20 oracles (#978)
- zh README rewritten to full parity with EN (was still describing the
  pre-dialect path model, missing the identity section, claiming 5.3.0)
- Last-updated stamp refreshed

* docs(readme): date the Linux corpus pass from the archive — 2026-09-27 wt4/linuxrun, 17/24 per its own ledger

The "(2026-09-26, #500)" tag was wrong on both counts: 09-26 is the
earlier "not-yet-usable" judgment (first smoke 8/10, gap-ledger C4) that
the 2026-09-27 wt4/linuxrun lane explicitly declared obsolete, and #500
only carried the figure forward — it is not the measuring record. No
archived record supports 19/24: the lane's own corpus-slice table
(docs/LINUX-RUN-STATUS.md, deleted in #478, archived in #477 section 4
and #581) tallies 17 suites at 0 diff + trap/redir/glob/extglob/new-exp/
read/ifs-posix with diffs = 17/24. README now reads "17/24 byte-identical
(2026-09-27 wt4/linuxrun lane, ledger archived in #477/#581)" in both
the platform-status paragraph and the compatibility table, EN + zh-CN
at parity. Addresses review comment 6319063190 on #982.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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