Skip to content

Conversation

@enebo
Copy link
Member

@enebo enebo commented Feb 18, 2025

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).

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.
@enebo enebo added this to the JRuby 10.0.0.0 milestone Feb 18, 2025
@enebo enebo merged commit 1196328 into jruby:10-dev Feb 18, 2025
56 of 73 checks passed
@enebo enebo deleted the fillnil branch March 4, 2025 18:30
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