Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@headius
Copy link
Member

@headius headius commented Nov 4, 2025

This PR will encompass some experiments with the implementation of Array:

  • Abstract RubyArray supertype to make it easier to support different backend implementations.
  • Concurrency-safe RubyArray backends that can efficiently handle multi-threaded mutation without raising errors.
  • Efficient specialized RubyArray backends for fixed sizes, immutability, or specialized data types (e.g. long[] for a homogeneous Array of Fixnums).

@headius headius force-pushed the abstract_ruby_array branch 6 times, most recently from cf09b04 to e8e1639 Compare November 4, 2025 02:25
@headius
Copy link
Member Author

headius commented Nov 4, 2025

The abstract work is proceeding; I have been force-pushing as I find broken ends of my refactoring.

I have tried to preserve as much of the public API of RubyArray as possible, even leaving most of the deprecated methods in place (they are apparently used by many of our extensions!) One area that is impossible to maintain is constructors, since they cannot be callable against an abstract class.

I believe only the following forms are public:

  • (Ruby, int)
  • (Ruby, IRubyObject[], int, int)
  • (Ruby, RubyClass, IRubyObject[])
  • (Ruby, RubyClass, IRubyObject[], int, int, boolean)

These are basically in order of risk, with the sized (Ruby, int) form being the most likely to be used in the wild.

The risk here is small, because these are peculiar forms and we have generally discouraged direct construction of core classes, but if some code out there does use these constructors there's no way to support that usage. The external code would have to be updated to use one of our factory methods.

Other risks largely revolve around any code that expects getClass() to be org.jruby.RubyArray, as I found in a few of our own tests, but this is less likely to be found in the wild.

@headius headius force-pushed the abstract_ruby_array branch 2 times, most recently from 2819431 to d74cb7a Compare November 4, 2025 03:10
@headius
Copy link
Member Author

headius commented Nov 4, 2025

I believe I have the abstractification green now with a minimal diff (outside of RubyArray.java). The remaining diffs are largely internal cases where we work directly with the "native" implementation from other core classes, such as to construct an uninitialized array for immediate population. These could be replaced with alternative forms.

The risks are outlined in my comment above, and mostly revolve around the irreplaceable constructor forms.

@headius headius force-pushed the abstract_ruby_array branch from d74cb7a to 2e5b6a5 Compare November 4, 2025 05:10
RubyArray will be split into RubyArray (abstract) and
RubyArrayNative (concrete) to support alternative implementations.
This commit makes the first stage a move, so that history can be
more easily tracked.
This is a first stab at making RubyArray an abstract class, which
will allow us to represent many different storage strategies as
Array as seen from Ruby code:

* The standard implementation, based on the CRuby logic, uses a
  native Java IRubyObject[] and supports full mutability and CoW
  sharing of that array.
* Two specialized implementations extend from this and provide one-
  and two-element versions of Array without an IRubyObject[] field.
  Making RubyArray itself abstract will make it easier to add more
  specializations.
* There are many useful collections provided by the JDK that could
  be used to implement Array. This change will allow them all to
  appear as the same Ruby type but with custom behaviors for
  specific use cases.
* This will make for an easier path to thread-safe Array, since we
  can have specialized implementations that all look like Array.

This is very much a prototype. I have tried to limit the changes
throughout the codebase by making RubyArray abstract rather than
introducing a new supertype (which would have to propagate through
all RubyArray signatures in the system). The goal is to keep all
RubyArray-consuming code the same as it is today while providing
multiple backend implementations.
@headius headius force-pushed the abstract_ruby_array branch from 2e5b6a5 to 956b746 Compare November 4, 2025 19:56
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.