Repository navigation
perf(array): hoist typed-cell read before mirror clone on element path - #924
Merged
Merged
Conversation
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).
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.
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.