Repository navigation
WIP: perf(assoc): answer settled assoc element misses from the typed cell (F3) - #1919
Merged
Merged
Conversation
A plain ${name[key]} expansion reaches the operator/array braced
handler only after the indexed handler's typed fetch returned None.
That handler re-derived assoc elements from the serialized storage:
a whole-storage clone plus the assoc_value_at linear scan per read,
which is Theta(n) per missed read (arrays.assoc_get_miss measured
13.96x GNU in the 2026-10-28 perf corpus; pristine probes: miss
245us vs GNU ~4us at n=10000), and it evaluated a side-effecting
subscript a second time where GNU evaluates it once per expansion
(subst.c:9777 parameter_brace_expand -> arrayfunc.c assoc_reference;
assoc.c assoc_reference is a single hash lookup, hit or miss).
The fetch's assoc branch already treats a miss as authoritative
whenever the freshness gate is open and a structured assoc cell
exists (rubash#616 Phase 1a invariant: the cell is a complete mirror
of the render). Add Executor::assoc_element_fetch_settled, which
re-derives exactly that admission on the same names, and let the
operator/array handler answer a settled miss directly. Every state
the fetch declines (unresolvable nameref, assoc mark absent, gate
closed, no assoc cell, the all-elements * form) keeps the storage
leg as the source of truth, unchanged.
Read side only; no write-path or mirror-sync changes (the VarTable
write funnel is a separate ruled lane).
Regression pins in tests/perf_assoc_element_miss_regressions.rs
assert GNU-observable behavior: hit/miss values after loop fill,
set-but-empty elements, unset-then-miss, single subscript
evaluation on hit and miss, operator/length forms over a miss,
declare -p shape after reads, function-local and nameref reads.
Expectations verified byte-for-byte against GNU bash 5.3.20.
caomengxuan666
marked this pull request as ready for review
October 28, 2026 06:49
This was referenced Oct 29, 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.
Family F3 — associative-array element read path (perf round 2026-10-28)
WIP — gates pending; do not merge yet.
Mechanism (measured, instrumented build of master 779b0cc)
The perf round attributed the assoc miss cost to the typed-fetch gate
staying closed after loop fill. Instrumentation of this tree shows the
gate is in fact OPEN after loop fill (dirty=false, the fetch serves
loop reads from the typed cell, zero mirror fetches on hits). The
Θ(n) miss cost lives one layer up:
expand_bracedtriesexpand_braced_indexed_parameterfirst; thetyped fetch returns the authoritative miss (None).
expand_braced_operator_or_array_parameter(src/executor/expand_braced_ops.rs), whose assoc leg re-derived the
element from the serialized storage:
parameter_array_storage(whole-storage clone) +
assoc_value_at(parse-cache hit + linearscan) — once per missed read. Probe counts at n=1000, 50 reads:
hit = 0 storage fetches; miss = 50 storage fetches + 50 scans.
(
assoc_subscript_key) a second time:declare -A m=([1]=one); x=${m[$((++i+5))]}lefti=2vs GNUi=1. This change restoressingle evaluation on the settled-miss path.
Fix (read side only)
Executor::assoc_element_fetch_settled(src/executor/arrays/executor.rs)re-derives the fetch assoc branch's own admission on the same names:
assoc-marked storage name (nameref-resolved), freshness gate open
(
!array_cells_dirty() || cell_is_fresh), structured assoc cellpresent, not the all-elements
*form.(
Some("")) and skips the storage leg. Every state the fetchdeclines keeps the storage leg unchanged as the source of truth.
(P-3) is a separate ruled lane and is untouched.
Behavior
GNU differential probes byte-identical (hit/miss values, set-but-empty
elements, unset-then-miss,
:-/${#}/+forms over a miss,declare -pshape and order, function-local and nameref reads), withone correction toward GNU: side-effecting subscripts on a miss now
evaluate once (was twice). Regression pins:
tests/perf_assoc_element_miss_regressions.rs (GNU bash 5.3.20
expectations).
Gates (to be filled in)
-D warningsclean