Repository navigation
perf(shopt): don't materialize default-equal state, keep fast lookup path - #915
Merged
Merged
Conversation
…path Root cause of the niu-vs-rubash gap (measured ~1us per simple command, ~0.5-2x on interpreter loops): a single redundant set_option call — e.g. hosts pinning expand_aliases off at startup, which equals the default — materialized $__RUBASH_SHOPT_STATE and flipped EVERY subsequent option_enabled lookup from the allocation-free static path to the serialized split-scan (plus per-command alias/arith/glob probes that ride on it). set_option now normalizes: state equal to the defaults removes the entry instead of storing it. Reads already treat absent as default, so shopt -p/BASHOPTS rendering is byte-identical. Verified on-device (aarch64, best-of-3): 30k empty-command loop niu 191ms -> 155ms vs rubash 150-158ms (gap closed, was ~25ms). New unit test locks the normalization in.
This was referenced Oct 20, 2026
Closed
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.
Root cause of the niu-vs-rubash gap
Measured on-device (aarch64, best-of-3, 30k empty commands): niu 191 ms vs rubash 150-158 ms — ~1 us of host overhead per simple command, scaling to ~0.5-2x on interpreter loops (niubash#352 matrix).
Bisected with a minimal reproducer crate (engine as path dep, niubash-like thin-LTO profile — same speed as rubash, so not codegen) down to one call: hosts pinning
expand_aliasesoff at startup. That single redundantset_optionmaterialized$__RUBASH_SHOPT_STATEand flipped every subsequentoption_enabledlookup from the allocation-free static path to the serialized split-scan — including the per-command alias gate and the per-eval/per-glob probes (#156/#157).Fix (
src/builtins/shopt.rs, +39/-1)set_optionnormalizes: a state equal to the defaults removes the entry instead of storing it. All readers already treat absent as default (state_containsNone arm,alias_expansion_enabled,shopt_state_enabled, histappend probe), soshopt -p/BASHOPTS rendering is byte-identical.Verification
redundant_writes_normalize_to_absent_state(+ deviation round-trip).wait_nunder load, passes 3/3 isolated and clean on re-run).