Repository navigation
perf(test): fast-expand [ $VAR -op N ] integer comparisons - #990
Merged
Merged
Conversation
GNU test.c:357 arithcomp (via valid_number, general.c:248-281) is the
spec; the decimal fast path (fast_decimal) already covered literal
operands, but every `$VAR` word missed the multi-word literal whitelist
and paid the full per-word expansion pipeline (pre-scans, brace and
positional probes, field-split checks, materialize).
gdb sampling, 30x on `while [ $i -lt 100M ]` (release): 9/30 in
expand_command_words/expand_command_word, 0 in execute_test_words,
valid_number, fast_decimal or fast_arith -- the comparison was never
the hotspot; expansion was.
New whitelist in expand_command_words (rubash#117 discipline -- doubt
falls through to the real pipeline): `[` (5 words) / `test` (4 words)
with one of the six integer operators, no expandable structure (shared
predicate), raw == word everywhere, literal operands via the shared
fast-literal predicate, and `$NAME` operands resolved through the
walker's unquoted `$name` chain (dynamic_parameter_value ->
shell_variable_value -> exact_case_env_var) gated on scalar (arrays,
assocs and namerefs keep the slow path), canonical fast_decimal value
(reused, never duplicated: `+12`/`007`/whitespace/empty/overflow keep
the slow path with exact GNU diagnostics) and no byte in the current
IFS (unquoted splitting provably identity). Quoted `"${..}"`,
positionals, unset and splittable values all decline. Construction
mirrors try_expand_literal_words_command field-for-field.
release best-of-3, Termux aarch64 (parallel builds contending, so read
the within-run delta): var-iso `[ $i -lt 15000 ]` vs literal-iso delta
152ms -> 70ms per 30k (5.1us -> 2.3us per operand); after-fix sampling
3/30 in expand (resolver + shared preserves_word_metadata scan), rest
is the shared dispatch floor (bash_command_text, set_current_command)
also paid by literals. Quoted `"[ $i ... ]"` unchanged (slow path).
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.
Variable-operand twin of the literal-words fast path: [ $i -lt N ] paid the full per-word expansion pipeline per iteration for a single scalar read. New whitelist try_expand_test_var_int_command resolves plain $NAME operands directly (same dynamic->shell->env chain as walker unquoted arm) when the value is canonical decimal (reuses builtins::test::fast_decimal, no second copy) and IFS-free. All doubt shapes fall through (quotes, positionals, unset/empty/non-canonical/splittable, arrays/namerefs, string ops, arity). Tests: lib 689 + new admission/construction unit test + coherence fuzz green; 35-case GNU differential identical. Loop-while 30k: ~2.4x->~1.8x vs bash.