Skip to content

perf(array): decimal-subscript write fast lane, alloc-free mirror append - #959

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/indexed-write-tail
Oct 21, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/indexed-write-tail

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

gdb: array write helpers already free (0% samples); the cost was re-entering the arithmetic subscript pipeline (15%). Fast lane for clean decimal cooked subscripts (word expansion already ran the single expand_arith_string pass; GNU arrayfunc.c:1368), which also fixes a real divergence: a[$((i++))]=v ran the side effect twice. Alloc-free mirror append; lazy lhs_as_written; old-element read only for +=. Tests: lib 670 + cli 469 green, 16 regression suites, 36-case GNU diff. Interleave 8k 3.65x->3.16x (-13.6%), 16k -12.1%.

…pend

The indexed element-write fill loop `a[$i]=$i` re-entered the whole
arithmetic-subscript pipeline for a subscript the word expansion had
already resolved. For a clean decimal cooked index that pipeline is pure
cost: GNU arrayfunc.c:1368 `array_expand_index` runs ONE
`expand_arith_string` + `evalexp` pass, and the cooked `index` IS that
product, so re-expanding the raw text ran a `$(...)` / `$((...))` side
effect a SECOND time (verified: `a[$(echo SIDE)]=v` prints SIDE twice on
master, once on GNU) and paid a full evalexp parse per element write.
Whitelist admission with the real pipeline as fallback: a single-quoted
raw span keeps the full path (GNU's arith pass leaves `'...'` literal
while the cooked text dropped the wrapper, so `a['7']` must keep
erroring), and every non-decimal cooked index is untouched.

Two more write-path costs removed, both in scope:

- `lhs_as_written` is now built lazily; only the bad-subscript error
  branches print it, so a successful write no longer pays the format!.
- `append_indexed_mirror_segments` appends the render segment directly
  (`[` + decimal + `]=` + quoted) instead of allocating a `format!`
  string plus a `quote_array_value` String per element. Plain
  double-quotable values (every numeric fill element) take the direct
  push; non-plain values still ride the full quoter, so the bytes stay
  identical to `format_indexed_array_storage` (unit-tested).
- the old element is read only for `+=`; a plain `=` no longer pays the
  structured-cell lookup (or a full mirror parse when there is no cell).

Measured on Termux/Android aarch64, release (opt-level 3, LTO), GNU bash
5.3.20 as reference, interleaved best-of-3, `a=(); for ((i=0;i<N;i++));
do a[$i]=$i; t=${a[$i]}; done`:

  8k:  baseline/bash 3.654x -> candidate/bash 3.157x (candidate/baseline 0.864x)
  16k: baseline/bash 3.729x -> candidate/bash 3.277x (candidate/baseline 0.879x)

gdb sampling of the write-only loop attributes the win: `eval_indexed_
subscript` fell from 15% of stacks to 0% and the write-path frame from
25% to 5%; the residual is generic word expansion (43%) and allocation
churn, outside this scope.

Verification: cargo fmt clean; cargo test --lib 670/670; array_store_parity
green with the store on and RUBASH_ARRAY_STORE=0 (new
`subscript_arith_side_effect_runs_once` case); cli_tests 469/469.
@caomengxuan666
caomengxuan666 merged commit cc0eeb4 into master Oct 21, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/indexed-write-tail branch October 21, 2026 08:03
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>
caomengxuan666 added a commit that referenced this pull request Nov 7, 2026
…2923 #2924) (#2993)

Fixes #2923
Fixes #2924

Captain-verified on head c0dd825: pins issue2923 12/0, issue2924 8/0, lib 1195/0/4 (base 1188 + 7 new lib tests), RUSTFLAGS="-D warnings" rc=0. The niubash prerequisite landed as niubash #959 (wildcard arm tolerating the new BindingSpec::Keymap variant); the canary leg is green on this generation. Net +1078/−71 across 7 files.

Bind prefix-meta now expands through the meta keymap with the shared fallback semantics, and inputrc old-style (unquoted) binding lines route through the same loader as quoted lines, carrying file/line diagnostics.

本 PR 删除了什么:无整文件删除;−71 行为被新路径取代的旧 bind 解析/注册代码(就地替换,非桥接)。
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