Skip to content

Eliminate fillnil from newArray#8619

Closed
enebo wants to merge 5 commits intojruby:masterfrom
enebo:less_filling
Closed

Eliminate fillnil from newArray#8619
enebo wants to merge 5 commits intojruby:masterfrom
enebo:less_filling

Conversation

@enebo
Copy link
Member

@enebo enebo commented Feb 9, 2025

This is a test but spec:ruby:fast does not break and I suspect it is because any operation which hits > realSize will fill at that point. Unsafe actions like eltOk always already know realSize.

Concurrent actions perhaps break less because we do this? We don't really make much in the way of guarantees so?

@enebo enebo added this to the JRuby 9.4.13.0 milestone Feb 9, 2025
@enebo
Copy link
Member Author

enebo commented Feb 9, 2025

In examining MRI's test_coverage I realized that this use of newArray relies on being able to set/aset into the 0 sized array and anything under whatever is alloc'd (16 by default) will already be nil-filled. If the source is greater than 16 then it nil fills 17+ as it marches on. If I make an empty array then it all just works.

To me, aset/set just assuming any alloc'd fields are already nil'd is a design failure on our part. The actual determinant should be realSize changing. If I elt(5) on an empty array which has a capacity of 16 0...4 should be nil-filled.

There are two usage patterns at play here and I think we picked the wrong one as a default:

  1. Allocate n elements and then incrementally add elements to the array (by far most common pattern). Right now we fill for this pattern and it has a measurable effect on every array we make.
  2. random access past realSize of the array. This means we need to materialize nils from old realSize to new realSize. By not pre-filling this could lead to more incremental nill fills.

I think conceptually it is simpler to assume primitive array is a backing store but that realSize is the boundary where we do work to fill in Ruby values.

@enebo enebo modified the milestones: JRuby 9.4.13.0, JRuby 10.0.0.0 Feb 11, 2025
@enebo enebo closed this Feb 18, 2025
@enebo enebo deleted the less_filling branch March 4, 2025 18:31
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