Repository navigation
perf: avoid cloning list values - #18636
Merged
Merged
Conversation
Store list `Value`s in `SharedCow<Vec<Value>>` so variable loads and captures retain shared backing storage until mutation. Keep mutation boundaries explicit and only materialize owned vectors for consuming operations. Preserve sharing in `first`, `last`, empty concatenation, and no-op flattening paths. Add copy-on-write regression coverage and Tango benchmarks for value cloning and stack variable loads.
Contributor
|
Thanks! |
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.
Description
Store list
Values inSharedCow<Vec<Value>>so clones share their backing allocation until mutation.Use copy-on-write storage at list mutation sites and only materialize an owned
Vec<Value>when an operation genuinely consumes the list. Preserve shared storage throughfirst,last, empty-list concatenation, and no-op flattening paths.Add tests for shared cloning and copy-on-write behavior, plus Tango benchmarks for cloning list values and loading them from the stack.
User-facing changes (Release notes)
Faster large list and table access
Large lists and tables are now much faster to read from, load from variables, and capture in closures.
Accessing a small part of a large list, such as
$list.0, no longer copies the entire list each time the variable is loaded. In a 100,000-element test, 200 repeated reads improved from roughly 131 ms to 138 µs (~950x faster).Additional notes
Tango results from 100 paired samples against current unpatched main:
list_value_clone_100000stack_list_get_var_100000Local end-to-end results for 200 repeated
$list.0reads:Perf is approximately constant as the list grows, removing the previous O(list length) cost from each variable load.