Repository navigation
perf(case): render head-only for $BASH_COMMAND, lazy word_chars, gated debug-trap head - #958
Merged
Merged
Conversation
…ollow-up) gdb sampling of a 20-literal-arm `case` loop (300 samples, release) plus the in-tree RUBASH_EXEC_PROFILE phase timers located the residual per-arm cost: it was not in the pattern matcher. `expand_case_pattern` borrows a static literal (zero `expand_word_mut`), `case_pattern_matches_with_word_chars` / `literal_pattern_equality` / `case_pattern_has_extglob` together were ~1% of samples, and the per-arm `word.chars()` collect was already hoisted by #921. The dominant arm-proportional cost was `set_current_command` (public_accessors.rs) rendering the WHOLE `case ... esac` text per execution into `__RUBASH_LAST_COMMAND` / `__RUBASH_CURRENT_COMMAND` (~2.8us/case for 20 arms; ~8% of the probe). GNU execute_cmd.c:3655-3665 resets `command_string_index` and prints only the head via `print_case_command_head` (print_cmd.c:731-739) before expanding the case word (3695-3699), so `the_printed_command_except_trap` — what `$BASH_COMMAND` exposes — is `case WORD in ` with WORD still carrying its source quotes. The clause list is rendered only for the JOB's `command` field (jobs.c make_job -> print_command), which rubash already obtains from `case_command_source_text` at background registration (compound_exec.rs:2791), so that path is unchanged. This also fixes a real divergence: `case "${BASH_COMMAND}" in 'case "${BASH_COMMAND}" in '*)` printed OTHER under rubash, HEAD under GNU bash 5.3 — rubash's case word expansion saw the full clause list. Cuts (all whitelist / de-duplication, GNU execute_case_command as reference): - public_accessors.rs set_current_command: case -> new `command_text::case_command_head_source_text` (`case WORD in `, raw word). - compound_exec.rs execute_case_command: gate the DEBUG-trap head `format!` on `has_active_trap_action(DEBUG)` (GNU run_debug_trap is a no-op with no armed action; same folded admission as the ast_exec preamble, rubash#186). - compound_exec.rs: the `word_chars` cache is now a lazy `Option<Vec<char>>` seeded only when an arm reaches the staged matcher — a literal-arm loop never builds it (GNU strmatch stages nothing for a literal). - compound_exec.rs: call `compound_command_has_redirects` once. Measured (interleaved min-of-11, release, local GNU bash 5.3.20): probe 32 (20 arms, miss all) 233.1 -> 208.9 ms (0.90x); vs bash 131.0 -> 1.59x probe 33 (20 arms, match arm0) 229.1 -> 205.9 ms (0.90x); vs bash 73.5 -> 2.80x loop baseline (no case) 183.4 -> 183.1 ms; vs bash 62.3 -> 2.94x The remaining multiplier is dominated by the shared per-command / `[` loop overhead outside case dispatch. Verified: cargo fmt; cargo test --lib 666 ok; case regressions (issue336/372/381/385/413/517/675/880) green; new tests/case_command_head_bash_command_regressions.rs 4 ok; a case semantic differential (glob/alt/fallthrough/nocasematch/extglob/quotes/comsub/ BASH_COMMAND/DEBUG) is byte-identical to GNU bash.
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gdb found the per-arm cost was NOT the matcher (0% in expand/match) but set_current_command rendering the whole case...esac text every arm. GNU execute_cmd.c:3655-3665 resets and prints head only (print_cmd.c:731). Also fixes a real divergence: case word expansion sees $BASH_COMMAND as the head, not the full text. Lazy Option<Vec> for literal arms; debug-trap head gated on has_active_trap_action(DEBUG). Tests: lib 666 + case regressions green, byte-identical vs bash. case 20-arm 10k: -10%; true case multiplier ~2.8x (shared dispatch is the rest).