Repository navigation
perf(expansion): #608 §2/§3 plain-literal removal single candidate + marker-free normalize skip - #1530
Merged
Conversation
…lize skip (rubash#608)
${v#pat}/${v%pat} with a plain-literal pattern previously paid one
matcher call per candidate boundary. GNU subst.c match_upattern
short-circuits a pattern that can match nowhere at a boundary, and
for a literal the only fragment that can match is the one of
exactly the pattern's length. remove_matching_prefix/suffix now
answer that class with a single candidate, applying the
byte-spelling gate and the marker-pair split exclusion in the same
order the boundary walk does; the class predicate is the new
pattern_is_plain_literal, extracted from literal_pattern_equality
so the matcher and the removal loops share one definition.
The ${v//pat/rep} dispatcher also skips the three allocating
backslash-normalize passes when the pattern carries neither
internal backslash marker (they are identity passes in that case).
Regression tests (expectations verified against the GNU bash
5.3.20 oracle from script files, including nocasematch leaving
removal matching case-sensitive):
issue_608_literal_removal_single_candidate,
issue_608_normalize_backslashes_marker_free_is_identity.
Verification: cargo build --locked ok; cargo test --lib 730
passed / 1 failed (ownership_unary_operators_check_existing_file,
the standing environment item); 246-case differential 244/2 with
failure set exactly {gl08, ms10}; 36-probe removal/substitution
battery byte-identical to GNU 5.3.20. Desktop debug bench: the
two-removal op delta over a plain assignment fell ~112 -> ~37
us/iter (within-run deltas; absolute ratios are debug-floor
dominated and not comparable to release numbers).
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.
Refs #608
Refs unixwin/niubash#352
What
Wave-4 andr slice: the two remaining variant items of rubash#608 §2/§3 that the desktop re-evaluation of the niubash#352 root causes (rubash#607–609) found still open on master, fixed with regression tests.
§3 — plain-literal removal tests a single candidate
${v#pat}/${v%pat}(and the##/%%forms) with a plain-literal pattern previously paid one matcher call per candidate boundary. GNUsubst.c: match_upatternshort-circuits a pattern that can match nowhere at a boundary; for a literal, the only fragment that can match is the one of exactly the pattern's length.remove_matching_prefix/remove_matching_suffix(src/executor/parameter_decode.rs) now answer that class with a single candidate, applying the byte-spelling gate and the marker-pair split exclusion in the same order the boundary walk does. The class predicate is the new sharedconditional::pattern::pattern_is_plain_literal, extracted from the matcher'sliteral_pattern_equalityso the matcher and the removal loops share one definition; glob/extglob patterns are unaffected (the literal class contains no operators by construction).§2 — marker-free normalize is skipped
The
${v//pat/rep}dispatcher rannormalize_parameter_pattern_backslashes(three allocatingreplacepasses) unconditionally. When the pattern carries neither the DATA_BACKSLASH nor the PATTERN_LITERAL_BACKSLASH marker, all three passes are identity, so it now returns a single copy (src/executor/parameter_replace.rs).Regression tests (in the lib test module, expectations from the GNU bash 5.3.20 oracle)
issue_608_literal_removal_single_candidateissue_608_normalize_backslashes_marker_free_is_identityThis raises the lib test count from 728 to 730 passed (the two tests above live in the lib target's test module); the single allowed failure remains the
ownership_unary_operators_check_existing_fileenvironment item.Same-round increments (desktop, debug build — do not compare with the Android release numbers in niubash#352)
Measured with the cluster's bench family, operator increment = case µs/iter − scalar-assignment control (b1) µs/iter, same round:
${s#Q}+${s%Q}increment${s//a/X}incrementMechanism check for s3: a 26-char value × 2 removals previously paid ~27 boundary matcher calls each; now a single candidate test each. Absolute µs across rounds are not attributable (the two rounds ran at different machine load; the b1 control dropped too) — only the same-round increments are claimed.
Verification (this slice, on top of master 6ae2a84)
cargo build --locked: OKcargo test --locked --lib: 730 passed / 1 failed / 1 ignored — the 1 failure is the allowedownership_unary_operators_check_existing_fileenvironment item; bothissue_608_*tests pass (the +2 over the 728 baseline is this PR's lib-module regression tests, see above)${v#h?llo}over a multibyte value under the POSIX locale — GNU's?is byte-based there (no match), rubash's matcher is character-based (full match). The baseline master binary (1e72c7f) produces the identical rubash output, and the pattern carries a glob operator so it never enters the literal path changed here. The cluster's own battery run on the fixed tree was fully equal; this case was added in the integration re-run and is recorded here rather than silently dropped.rustfmt --checkon the three files), CR count 0. (cargo fmt --check -- <files>additionally surfaces pre-existing master fmt debt in untouched files — e.g.src/builtins/kill.rsshows the identical diff taken verbatim from master — not introduced by this PR.)Status of #607–609 after this slice (from the cluster re-evaluation)
//re-derivationLiteralMatchesstill stages two Vecs per call#/%boundary matchingThe structural remainder (#607 §3/§4/§8, #609 §2 convergence, #608 §2
LiteralMatchesstaging) belongs to the performance line (shellbench gap baseline), not this issue — hence Refs, not Fixes. Android-side conclusions in niubash#352 (RSS 2.2×, fork-bound rows, on-device release ratios) still need a device release re-measurement.