Repository navigation
perf(executor): dispatch-floor residue - shape-only cd/pwd comsub admission, DEBUG-trap parse-once cache (rubash#375) - #562
Merged
Conversation
…(rubash#375) Attribution (temporary phase timers over the release build, removed before landing): $(cd X && pwd) paid the single-handle canonical round trip (CreateFileW + GetFileInformationByHandle + GetFinalPathNameByHandleW, ~99us in-process) TWICE per substitution — the admission probe (command_substitution_uses_specialized_path) ran the full helper via command_substitution_cd_pwd_output_quiet_probe and discarded the result, then the real expansion paid the whole round trip again. Admission never needed any of it: the helper returns Some for EVERY body passing its shape gate (both failure arms yield Some(String::new()) with status 1), so the probe reduces exactly to the shape predicate. The predicate is now one shared function (command_substitution_cd_pwd_shape) used by both the admission and the real expansion — single source of truth, no divergence possible. Construction-only, pinned equivalence: - admission set unchanged (same split functions, same shape conditions, independent of expansion results); - the removed probe pass also expanded the cd target and wrote last_command_substitution_status BEFORE the real pass — GNU expands the cd target exactly once at cd execution (subst.c), and a side-effecting target ($(cd $(echo n >> cnt; echo d) && pwd)) now appends once where master appended twice; WSL GNU Bash 5.3.0 probe: lines=1, matching the new behavior; - cd failure diagnostics still print exactly once (the quiet-probe suppression existed only to mask the double run). A/B (interleaved rounds, same host, release builds of db3218a vs this tree, medians/mins): $(cd X && pwd) x2000 -34.2%/-38.4%; x5000 plain loop -30.6~-34.7%/-36.3%; x5000 inside function -28.7~-33.5%/-33.9%. No-trap canaries flat (noop_colon +0.3~0.8% median, mins equal). 21-shape semantic battery (normal/missing/file-not-dir/bare-cd/../ trailing-slash/semicolon/pwd -P| -L/rejected shapes/side-effect-once/ status propagation/xtrace disqualification/nested/quoted/exotic): stdout+stderr+rc byte-identical to master except the intended once-only target expansion.
Attribution (temporary phase timers over the release build, removed before landing): run_debug_trap re-tokenized and re-parsed the action text on EVERY firing — measured 12.5us x 6002 firings (75ms of 4.0s) in the bats_debug_trap shape (trap body = function call + cd/pwd comsub + two special-array copies). GNU parses a trap action once at trap invocation (trap.c read_trap_action) and runs the cached parse per firing. Mechanics: key = the alias-spliced action text (the exact bytes tokenize sees), value = the parsed AST in a RefCell on the Executor. Per firing the AST is TAKEN out of the cell (the existing per-firing command.line stamp walk mutates it), executed, and put back — a stable action text pays zero clones and zero parses; any change to the spliced text (trap re-set, alias-table change feeding the splice, empty->armed transition) misses and re-parses. The early-return guards (already running, host-internal depth) sit before the cache and never touch it, so re-entrancy cannot double-take. The RETURN trap keeps its own path. Construction-only: a same-text re-parse is deterministic (plain tokenize+parse, no executor state input), and the stamp walk unconditionally overwrites every top-level command line per firing, so a reused AST is re-stamped exactly as a fresh parse would be. Aliases expand at execution from the live table (parse.y alias_expand_token ports) — unchanged. A/B (interleaved rounds, same host, release builds, medians/mins): bats_debug_trap shape -28.8%/-29.3% (9 rounds); with the first cut of this series the same lane reads -32.6%/-28.2% (7 rounds). No-trap and array-copy canaries flat (mins equal, medians within noise). Verification: 21-shape DEBUG battery (LINENO/BASH_COMMAND, loop and function firings, trap re-set inside action, alias text evolution after the trap is armed, functrace inheritance, ERR/RETURN adjacency, same- text re-arm, nested cd/pwd comsub inside the action, exit-2 terminal skip) byte-identical to master; full cargo test --no-fail-fast failure sets bidirectionally identical to fresh origin/master (4432 passed / 55 failed / 170 suites on BOTH sides, per-suite counts identical).
This was referenced Oct 12, 2026
caomengxuan666
added a commit
that referenced
this pull request
Oct 13, 2026
…601) 40 commits (PRs #496-#600) folded into [1.4.0] by theme instead of per-commit listing: - GNU semantics waves 1-4b with their issue families - argv re-expansion P0 pair (#511/#555), PWD POSIX persona (#537) - -s on-demand stdin driver as the canonical library reader (#586) - CLI entry-shape semantics (#589-#591) and the GNU usage contract (#585) - diagnostic message fidelity (#551) and parser diagnostic tokens - Windows path contract (#568/#592) - lexer/executor performance rounds (#554/#562/#501) - docs: boundary invariants, platform gap, baselines, debugger M0 Commit message deliberately carries no release/version claim.
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.
Continues #375 (after #484's single-handle cut). Follows the #501/#554 playbook: profiled attribution -> construction-only fixes with pinned equivalence -> interleaved A/B -> full-suite failure-set parity. Not merged by this agent; leaving review/merge to the captain. Two commits, one per fix; every temporary attribution probe was removed before landing (the shipped diff carries none of it).
Attribution (release build;
RUBASH_EXEC_PROFILEphase timers, all removed; samply/ETW sampling is dead on this host — 11-14 samples per run — so attribution ran on phase decomposition + targeted standalone probes)$(cd X && pwd)paid the canonical round trip TWICEcommand_substitution_uses_specialized_path) ran the full cd/pwd helper (expand_word +shell_path_to_windows+ single-handlecanonical_physical_dir: CreateFileW+GetFileInformationByHandle+GetFinalPathNameByHandleW, ~99µs in-process) and discarded the result; the real expansion paid it againrun_debug_trapsplice+tokenize+parse = 12.5µs x 6002 firings (75ms of 4.0s) in the bats_debug_trap shapechain0.6µs/cmd,empty2.9µs/cmd, total floor ~12-16µs/cmd incl. ~7µs/iter loop machinery; the #375 bats-context 56µs/46µs figures were trap-firing work (this PR cuts most of the remainder)Fixes (one commit each)
command_substitution_cd_pwd_shapepredicate replaces the full-probe admission. Pinned equivalence: the helper returnsSomefor EVERY shape-matching body (both failure arms yieldSome(String::new())+ status 1), so admission is decidable from word shape alone. Side bonus toward GNU: the removed probe pass expanded the cd target (and wrote the comsub status) before the real pass — a side-effecting target$(cd $(echo n >> cnt; echo d) && pwd)now appends ONCE (WSL GNU 5.3.0 probe: lines=1; master appended twice).RefCell; per firing the AST is taken out, line-stamped (the existing unconditional stamp walk), executed, put back. Stable text = zero clones, zero parses per firing (GNU parses once attrapinvocation, trap.c read_trap_action). Re-entrancy guards sit before the cache; RETURN trap untouched.Before/after (release, same host, interleaved rounds, base = fresh
origin/masterbuild; median/min)$(cd . && pwd)+ 2 array copies) x2000$(cd X && pwd)x2000 plain loop$(cd X && pwd)x5000$(cd X && pwd)x5000 in function:x20k (no-trap canary)Honesty note: what is NOT fixed, and why
$(cd && pwd)resolves, which is GNU-owned behavior. Structurally closed at this layer.BATS_DEBUG_LAST_LINENO=(...)renders the snapshot into indexed storage, ~40µs each): reads are already live-view O(n) after the first [perf] bats-core wall-clock ~10x GNU: DEBUG-trap dispatch ~0.4-1ms x ~2300 firings/gather + per-firing $(cd;pwd) path normalization #375 cut; the store render needs the structured-variable-store lane (same family as perf(executor): hot-path residue — test marks gate, word materialization once, assignment scan admission (rubash#242) #501's deferredapply_shell_assignmentnote). Not a safe spot patch; deferred.$?(GNU=1, rubash=0): separate tracked semantic issue ([perf] bats-core wall-clock ~10x GNU: DEBUG-trap dispatch ~0.4-1ms x ~2300 firings/gather + per-firing $(cd;pwd) path normalization #375 item 3), untouched here.Verification
cargo test --no-fail-faston this branch vs a freshorigin/masterbuild: failure sets bidirectionally identical by name (55 failures on BOTH sides; 170 suites parsed, per-suite (result, passed, failed) counts identical; totals 4432 passed / 55 failed each — the known host-env families).../trailing-slash/semicolon/pwd -P/pwd -L/rejected shapes/side-effect-once/status propagation/xtrace disqualification/nested/quoted/exotic; DEBUG trap: LINENO/BASH_COMMAND, loop+function firings, re-set inside action, alias text evolution after arming, functrace inheritance, ERR/RETURN adjacency, same-text re-arm, nested comsub in action, exit-2 terminal skip): stdout+stderr+rc byte-identical to master except the single intended diff (side-effecting cd target now expands once, GNU-anchored).cargo fmtclean; diff is 5 files, +92/-53.