Skip to content

object_id improvements#9084

Merged
headius merged 5 commits intojruby:masterfrom
headius:object_id_improvements
Dec 1, 2025
Merged

object_id improvements#9084
headius merged 5 commits intojruby:masterfrom
headius:object_id_improvements

Conversation

@headius
Copy link
Member

@headius headius commented Nov 19, 2025

A set of small improvements for object_id, inspired by Ruby 4.0 object_id optimizations and with an eye for future removal of _id2ref.

Ideas to try:

  • Reduce reads of volatile fields in lazy variable accessors.
  • Use the smallest java.lang.Number box for a given ID.
  • Propagate ThreadContext to avoid getting runtime the slow way.
  • Use long rather than IRubyObject in MRIRecursionGuard. (rejected as this is unused, deprecated code and the replacement does not use object_id)
  • Cache RubyInteger version after access, to avoid constructing it repeatedly. (rejected for now; storing RubyFixnum would negate size optimizations above and an alternative box requires more thought)

This also opens up the possibility of using a BigInteger in the
future, if overflow becomes a problem.
@headius headius added this to the JRuby 10.0.3.0 milestone Nov 19, 2025
This may eventually avoid the roundtrip through runtime, so use it
now.
@headius headius merged commit ff8c280 into jruby:master Dec 1, 2025
74 of 77 checks passed
@headius headius deleted the object_id_improvements branch December 1, 2025 18:32
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