Skip to content

perf(array): hoist typed-cell read before mirror clone on element path - #924

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/array-read-hoist
Oct 20, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/array-read-hoist

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Follow-up to #923. array_element_parameter_value_uncached fetched the whole mirror (O(n) clone) before the typed-cell fast path. Reordered: subscript expansion (side effects preserved) -> dynamic divert -> typed-cell (dirty-gated, zero-clone hit) -> lazy mirror only on miss. Assoc leg untouched. GNU: arrayfunc.c:1492 array_value_internal, :1356 array_expand_index, :1448 array_variable_part, expr.c:1183. Tests: lib 639 + cli 467 green; probes byte-identical vs bash 5.3.20. Release interleave 8k: 3.87x -> 2.99x.

GNU arrayfunc.c:1492 array_value_internal orders the read as
array_variable_part (arrayfunc.c:1448 variable lookup) ->
array_expand_index (arrayfunc.c:1356 expand_arith_string + evalexp,
expr.c:1183 expr_streval) -> array_reference (element fetch), with the
explicit comment to expand the index even if the variable does not
exist in case side effects are needed (${w[i++]} where w is unset).
The mirror fetch is a pure read, so it moves after the subscript
expand+evalexp pass (side-effect order preserved); assoc/dynamic/
scalar divert legs are untouched, only the indexed typed leg moves.
The dirty flag still gates the cell and the debug_assert still
compares against an on-demand mirror fetch (release compiles out,
skipping the per-read O(n) clone on a typed hit).
@caomengxuan666
caomengxuan666 merged commit a53aeaa into master Oct 20, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/array-read-hoist branch October 20, 2026 15:34
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