Skip to content

perf(executor): skip the per-eval arith ticket for read-only shapes (#607) - #671

Merged
caomengxuan666 merged 1 commit into
masterfrom
perf/issue607-arith-ticket
Oct 16, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
perf/issue607-arith-ticket

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

perf(executor): skip the per-eval arith ticket for read-only shapes (#607)

What

Even identity-alphabet (( )) expressions paid the full post-expansion
ticket per evaluation: array_expand_once shopt lookup, nounset
lookup+scan, EXP_EXPANDED insert/remove, ARITH_WRITES pre-clear, the
dynamic-context snapshot (per-eval clones, getpid), and the write
sync. GNU evaluates (( )) via execute_arith_for_command
(execute_cmd.c:3219) — unlike eval_arith_for_expr (:3163, the let
path passing EXP_EXPANDED per expr.c:340,368) it never marks its
operand already-expanded, so for the expand caller every
EXP_EXPANDED item is provably a no-op; expand_arith_string
(subst.c:3981) leaves the identity alphabet untouched.

Fix

Two-gate whitelist at the top of the ticket: syntax shape (identity
alphabet + fast_arith_ticket_shape: no =/++/-- ⇒ read-only, no
dynamic-context names, no __RUBASH_) and state (write log empty on
entry; every spelled identifier unset or plain-decimal, so no nested
evaluation can observe a skipped item). Any doubt falls through to the
full ticket. let/non-identity paths are byte-identical. Preserved:
DEBUG-trap/xtrace/LINENO (fired by the command loop around this call),
nounset (identifier-free text skips only the provably-vacuous scan),
EXP_EXPANDED consumers, readonly + subscript diagnostics.

Measured (release, order-rotated min)

Headline for ((i...)); do :; done: no significant delta
(parser+dispatch+loop dominate). Dense 200k read-only (( )) probe:
eligible ~8% faster than ineligible shape on the same binary (net
ticket saving ≈5%, ~200ns/eval). Small but real; the loop-machinery
half stays separate.

Verification

  • New fast_arith_ticket_tests (6 tests): shape admit/reject, decimal
    gate, fast==slow value+side-effect contract incl. let parity,
    nounset, slow-fallback semantics.
  • cargo test --lib green; cargo fmt --check clean.
  • Byte-identical fast-vs-base differentials: loop/inc/octal/let/
    assoc/indexed/RANDOM/LINENO/BASHPID/nounset + readonly/
    array_expand_once/DEBUG-trap/LINENO/BASH_COMMAND scripts.
  • Full serial failure-set gate vs master: per-target results
    byte-identical across legs (the tool's cli_tests NEW-target row is
    the known parse artifact). Test-level 3 NEW / 1 DISAPPEARED, all four
    in the known-nondeterministic part_080 coproc family (all pass in
    isolation on branch). Failing-test totals symmetric (1252=1252).
  • niubash product A/B (niubash pinned 6295367, only rubash [patch]
    switched): failure sets byte-identical (49=49).

…607)

Even identity-alphabet (( )) expressions paid the full post-expansion
ticket per evaluation: array_expand_once shopt lookup, nounset
lookup+scan, EXP_EXPANDED insert/remove, ARITH_WRITES pre-clear, the
dynamic-context snapshot and the write sync. GNU evaluates (( )) via
execute_arith_for_command (execute_cmd.c:3219), which never marks its
operand already-expanded (unlike eval_arith_for_expr :3163, the let
path per expr.c:340,368), so every EXP_EXPANDED item is a no-op for the
expand caller; expand_arith_string (subst.c:3981) leaves the identity
alphabet untouched.

Two-gate whitelist: syntax shape (no =/++/-- = read-only, no dynamic
names, no __RUBASH_) and state (write log empty; identifiers unset or
plain-decimal). Any doubt falls through. let/non-identity paths
byte-identical. DEBUG-trap/xtrace/LINENO, nounset, EXP_EXPANDED
consumers, readonly/subscript diagnostics preserved.

Dense 200k read-only (( )) probe ~5% (~200ns/eval); headline loop
unchanged (dispatch+loop dominate). 6 contract tests; lib green.
@caomengxuan666
caomengxuan666 merged commit 2753e4b into master Oct 16, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the perf/issue607-arith-ticket branch October 16, 2026 14:32
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