Remove upfront fillNill in Array #8636
Merged
+23
−13
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.
fillNil does a bunch of extra nil sets up to the capacity of the array whether those values ever end up getting used.
The rationale for this fix is anything >realSize should get nil'd only after we change realSize. For appends this never happens. The case where it does happen is in aset. In this case we nil fill between oldRealSize and one less than new realSize.
From a performance analysis all arrays initially benefit from not pre- filling nil up to capacity (which is 16 by default). For arrays which are doing arbitrary asets past the end of the array it could end up doing more fills but asets like this are pretty uncommon. Most of the time I do not even think it would be doing more fills for this either.
Additionally I removed the unshift for one extra element for shaped arrays. The logic here is if you are unshifting once you likely are unshifting more than once so this buys very little. I may be doing a followup here to make unshift/prepend better at allocating space as it only does it in a very limited case (an empty array and only for 16 prepends).