Skip to content

perf(expansion): #608 §2/§3 plain-literal removal single candidate + marker-free normalize skip - #1530

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix4/slice-andr
Oct 25, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix4/slice-andr

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

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. GNU subst.c: match_upattern short-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 shared conditional::pattern::pattern_is_plain_literal, extracted from the matcher's literal_pattern_equality so 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 ran normalize_parameter_pattern_backslashes (three allocating replace passes) 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_candidate
  • issue_608_normalize_backslashes_marker_free_is_identity

This 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_file environment 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:

case baseline round this round
s3 ${s#Q}+${s%Q} increment 111.9 µs 37.3 µs (≈3× cheaper)
s2 ${s//a/X} increment 137.5 µs 79.7 µs
s5 four-operator composite, per operator ≈284 µs ≈126 µs

Mechanism 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: OK
  • cargo test --locked --lib: 730 passed / 1 failed / 1 ignored — the 1 failure is the allowed ownership_unary_operators_check_existing_file environment item; both issue_608_* tests pass (the +2 over the 728 baseline is this PR's lib-module regression tests, see above)
  • 36-probe removal/replacement battery (literal / glob / spaces / multibyte / nocasematch / escaped backslash) against the GNU 5.3.20 oracle: 35/36 byte-identical (stdout+stderr+rc). The one diff is pre-existing and outside this PR's scope: ${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.
  • 246 differential suite: full run 243 PASS / 3 FAIL = {gl08, bi08, ms10}; bi08 is the known timing race — 5/5 isolated re-runs pass on this slice's binary (same adjudication as the dcl slice), so the stable failure set is exactly {gl08, ms10}, the standing baseline set. The cluster's run on the fixed tree read 244/2 with the same stable set.
  • Changed files rustfmt-clean (direct rustfmt --check on 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.rs shows the identical diff taken verbatim from master — not introduced by this PR.)

Status of #607–609 after this slice (from the cluster re-evaluation)

item verdict
#607 §1 eval ticket variant — fast ticket in place; residual: one unconditional subscription-expr remove per eval entry
#607 §2 lvalue resolution fixed earlier (borrowed name, mark check first)
#607 §3 scalar read clone still present (structural)
#607 §4 write chain dual-store + replay still present (structural), narrowed by §1 sync gating
#607 §5 CommandNode rebuild fixed earlier (literal command fast path)
#607 §6 per-command probe chain variant — throttled on Windows; chain still present
#607 §7 loop-entry deep copy fixed earlier (borrowed header/body + counter fast loop; empty arith-for measures 0.74× of GNU in desktop debug)
#607 §8 per-eval re-parse still present (at parity with GNU evalexp per the issue itself)
#608 §1 case modification fixed earlier (GNU casemod.c model)
#608 §2 // re-derivation this PR: marker-free normalize skip; residual: LiteralMatches still stages two Vecs per call
#608 §3 #/% boundary matching this PR: plain-literal single-candidate path (literal case of GNU's matches-nowhere short-circuit)
#608 §4 result copy-back variant, rides on #609
#609 §1 assignment memo fixed earlier (gated on xtrace)
#609 §2 dual store variant — marks-free in-place fast bind mitigates; structure not converged
#609 §3 nameref pre-allocation fixed earlier (borrowed-name mark check)

The structural remainder (#607 §3/§4/§8, #609 §2 convergence, #608 §2 LiteralMatches staging) 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.

…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).
@caomengxuan666
caomengxuan666 merged commit 50907be into master Oct 25, 2026
5 of 8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix4/slice-andr branch October 30, 2026 01:41
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