Skip to content

perf(executor): if-condition dispatch residual (#661) - #673

Merged
caomengxuan666 merged 1 commit into
masterfrom
perf/issue661-ifcase
Oct 16, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
perf/issue661-ifcase

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

perf(executor): if-condition dispatch residual (#661)

What

Per-execute_command if/case dispatch residual (~2.5x): the alias-scan
ran expand_aliases() (a words.to_vec() + per-word table probes) per
body command, and every :/true condition paid
inside_compound_condition save/restore + `with_errexit_suppressed
wrapping.

Fix (whitelist-only, two slices)

  • Alias scan: with an empty alias table (or alias-streamed words) the
    raw first word IS the expanded first word — check it directly.
    Mirrors expand_aliases' own early-outs; a stateful cross-exec cache
    was rejected (aliases/shopt mutate at runtime; needs
    generation-counted invalidation).
  • Condition state: a single bare :/true with every
    assignment/redirect/substitution/pipe/wrapper channel empty runs
    unmarked. Review-caught soundness gate: a shadowing function/alias
    makes the word execute user code that can fail (a true() returning
    nonzero under set -e must keep the slow path's suppression), so
    shadowed words fall through.

GNU owners: execute_cmd.c:3862 execute_if_command, :5200
pointer walk, parse.y alias no-op on empty table.

Measured (release, N=200k, order-rotated min-of-5)

#607 already took the big chunk. Toggles alone are below the noise
floor; the alias slice wins where it fires: 50-cmd never-executed else
body with empty table, 8.916s → 6.636s (−26%, −0.22µs/scanned command);
non-empty-table probe at parity (correct slow path).

Residuals for follow-ups (measured, out of scope): shape-independent
per-execute_command cost ~2.8µs; set_current_command render scaling;
if…fi >/dev/null redirect path +52µs.

Verification

  • ifcase_diff.sh 55/55, casearm_diff.sh 29/30 (only pre-existing
    Fix Winuxsh framework glob loading and hook dispatch #17) vs GNU; alias+if differentials byte-identical.
  • New issue661_if_condition_shadow_regressions (4 tests, incl. the
    review-caught true()/alias + set -e divergence).
  • cargo test --lib 585/585; focused case/alias/trap/errexit suites
    green.
  • Full serial failure-set gate vs master: no NEW failing targets after
    exoneration (the cli_tests NEW was 9 examples tests failing on a
    worktree-empty third_party/bash submodule — 9/9 green after
    git submodule update --init). Test-level 1 DISAPPEARED
    (part_080 coproc, passes in isolation on branch). No regression.
  • niubash product A/B (niubash pinned 6295367, only rubash [patch]
    switched): 50 vs 49, the single extra
    (epochrealtime_beats_external_date_for_timing) is the known load
    flake — green in isolation on branch.

Per-execute_command if/case dispatch: alias-scan ran expand_aliases
(Vec clone + per-word probes) per body command; every :/true condition
paid inside_compound_condition save/restore + errexit-suppression wrap.

Empty alias table (or alias-streamed words): raw first word IS the
expanded first word, checked directly. Bare :/true with all channels
empty runs unmarked; shadowed words (function/alias) fall through to
keep slow-path errexit suppression (review-caught: true() returning
nonzero under set -e).

50-cmd else body -26%; guards 55/55 + 29/30 (pre-existing #17 only);
4 shadow regression tests.

GNU: execute_cmd.c:3862 execute_if_command, :5200 pointer walk.
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