Repository navigation
perf(executor): zero-alloc static case-arm patterns (#662) - #669
Merged
Merged
Conversation
expand_case_pattern ran the full word-expansion pipeline plus ~5
String layers per clause per exec even for static literals. GNU
re-expands dynamic patterns per arm (execute_cmd.c:3686/3712
expand_word_leave_quoted, match via match.c/cond.c) but a static
literal trivially expands to itself.
Whitelist classifier (default-deny on both text and raw_text; rejects
$, backquote, quotes, backslash, ~ { < > and all carrier/control
chars; probed GNU tilde-in-pattern HIT) returns Cow::Borrowed with no
alloc; anything else takes the byte-identical slow path. nocasematch
was already hoisted; matcher selection stays syntax-based.
Measured (release, rotated min-of-3, 20k iters): per-arm slope
~2.5us -> ~1us (n=16 literal -39%). Guards: casearm 29/30 (only
pre-existing #17), ifcase 55/55, lib 588/588.
This was referenced Oct 16, 2026
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.
perf(executor): zero-alloc static case-arm patterns (#662)
What
expand_case_patternran the full word-expansion pipeline + ~5 Stringlayers per clause per exec, even when the pattern is a static literal.
GNU re-expands dynamic patterns per arm (
execute_cmd.c:3686/3712expand_word_leave_quoted, match viamatch.c/cond.c) — a staticliteral trivially expands to itself.
Fix
Default-deny whitelist classifier over both stored
textandraw_text: only inert chars admit (rejects$, backquote, quotes,backslash,
~{<>}, controls, all PUA carrier markers — tilde probed:HOME=/tmp/h; case /tmp/h in ~)is a HIT in GNU, so~fallsthrough). Admitted arms return
Cow::Borrowed, zero alloc, pipelineskipped; everything else takes the byte-identical slow path. No shopt
semantics moved (
nocasematchwas already hoisted; matcher selectionstays syntax-based).
Measured (release, order-rotated min-of-3, 20k iters, N arms)
Per-arm slope ~2.5µs → ~1µs (residual = matcher + loop machinery).
Verification
cargo test --lib588/588;cargo fmt --checkclean.casearm_diff.sh29/30 (only pre-existing Fix Winuxsh framework glob loading and hook dispatch #17, untouched slow path);ifcase_diff.sh55/55 vs GNU.case_arm_static_tests(3 tests): static shapes borrow, dynamicshapes take the slow path with correct expansion, 9 script shapes match
GNU exit codes.
(NEW=0/DISAPPEARED=0). Test-level NEWs all exonerated: 9
cli_tests::examples= worktree-missing-submodule artifact(
third_party/bashempty in fresh worktrees —git submodule update --init+ re-run 9/9 green); 5part_080coproc = known flake family(all pass in isolation on branch);
unclosed_arithmetic_subscriptfails identically on both legs in isolation (shared, order-dependent).
6295367, only rubash[patch]switched): failure sets byte-identical (49=49).