Skip to content

perf(executor): arith-for loop machinery without per-iter rebuild (#607) - #679

Merged
caomengxuan666 merged 1 commit into
masterfrom
perf/issue607-loop-machinery
Oct 16, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
perf/issue607-loop-machinery

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

perf(executor): arith-for loop machinery without per-iter rebuild (#607)

What

Slices 1+2 (#665, #671) took dispatch and the eval ticket; the loop
machinery itself still paid per iteration: body.to_vec() + a fresh
execute_ast wrapper (mutex lock, evalerror-flag resets, locale-map
clear, summary probe), per-evaluation DEBUG miss-path consults, and a
full reap scan on an empty job table. GNU re-walks the stored body by
pointer (execute_cmd.c:3219) and consults traps per evaluation
(:3163).

Fix

  • Body runs via execute_ast_inner(body) on the borrowed slice (what
    while/until/for-in already use) — no per-entry Ast clone, no
    reader-level wrapper per iteration.
  • DEBUG consult gated behind has_active_trap_action (2 lookups, no
    alloc), re-probed after the body (which can install/remove the trap
    — first version hoisted to loop-top and missed the update fire; the
    contract test pins it).
  • Test/update emptiness trimmed once per loop entry (header borrowed
    from the parsed node).
  • reap_dead_jobs_after_loop_body early-returns on an empty job table
    (helps all loop kinds; GNU :3267 REAP()).

Measured (release, N=200000 for ((i=0;…)); do :; done, rotated min-of-5)

GNU 889ms · base 1445ms · after 1396ms (~3.4%, ~250ns/iter; 1.63x →
1.57x GNU).

Verification

  • New issue607_arith_for_loop_machinery_regressions (6 tests: DEBUG
    fire counts + for-line LINENO, mid-loop install/remove, xtrace,
    break 2/nesting, wait).
  • Upstream arith-for/arith/dbg-support scripts byte-identical
    base-vs-after.
  • cargo test --lib 594/594; trap/debug/arith/eval/nounset/break
    suites green (2 trap failures are Android-signal environment,
    identical on base).
  • Full serial failure-set gate vs master: per-target results match
    except the new regression file itself (6/6) and the perf(executor): marks-free scalar bind without the dual-store walk (#609) #678-extended
    contract file (master leg predates perf(executor): marks-free scalar bind without the dual-store walk (#609) #678: 4 vs 7 — drift, not
    regression). Test-level 4 NEW, all in the known-nondeterministic
    part_080 coproc family (all pass in isolation on branch).
    No regression.
  • niubash product A/B (niubash pinned 6295367, only rubash [patch]
    switched): failure sets byte-identical (49=49).

Body runs via execute_ast_inner on the borrowed slice (no per-entry
Ast clone, no reader wrapper per iter); DEBUG consult gated behind
has_active_trap_action with post-body re-probe; test/update emptiness
trimmed once; reap early-returns on empty table. GNU execute_cmd.c:3219
pointer re-walk, :3163 per-eval trap consult, :3267 REAP.

N=200k : loop 1445ms -> 1396ms (~3.4%). 6 contract tests; upstream
arith-for/arith/dbg-support byte-identical.
@caomengxuan666
caomengxuan666 merged commit 116e571 into master Oct 16, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the perf/issue607-loop-machinery branch October 16, 2026 16:10
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