summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJeremy Evans <[email protected]>2024-01-26 13:35:37 -0800
committerJeremy Evans <[email protected]>2024-01-27 11:42:01 -0800
commit223910b329751fbee36efe66ccd544e66dbe90f8 (patch)
tree3f17af97b86d0a206829695da044a71af9f97fb4 /lib
parente337c9478a1c5d60b6cfa4ddbee71523a7f8bd84 (diff)
Reduce array allocations for literal arrays with splats and other args
Previously, a literal array with a splat and any other args resulted in more than one array allocation: ```ruby [1, *a] [*a, 1] [*a, *a] [*a, 1, 2] [*a, a] [*a, 1, *a] [*a, 1, a] [*a, a, a] [*a, a, *a] [*a, 1, *a, 1] [*a, 1, *a, *a] [*a, a, *a, a] ``` This is because previously Ruby would use newarray and concatarray to create the array, which both each allocate an array internally. This changes the compilation to use concattoarray and pushtoarray, which do not allocate arrays. It also updates the peephole optimizer to optimize the duparray/concattoarray sequence to putobject/concattoarray, mirroring the existing duparray/concatarray optimization. These changes reduce the array allocations for the above examples to a single array allocation, except for: ``` [*a, 1, a] [*a, a, a] ``` The reason for this is because optimizing this case to only allocate 1 array requires changes to compile_array, which would currently conflict with an unmerged pull request (#9721). After that pull request is merged, it should be possible to refactor things to only allocate a 1 array for all literal arrays (or 2 for arrays with keyword splats).
Diffstat (limited to 'lib')
0 files changed, 0 insertions, 0 deletions