Avoid use of id2ref for weak mapping on JRuby #31
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.
Revisiting my report in https://bugs.ruby-lang.org/issues/15711 and trying to finally get rid of the use of
ObjectSpace._id2ref
in drb. That report was closed but never actually fixed in DRb.The implementation of
ObjectSpace._id2ref
on JRuby (and TruffleRuby) is very expensive, and on JRuby we normally do not have it enabled because it impacts performance of the entire runtime.This alternate implementation uses the
weakref
library to build a weak ID map. It could possibly use the new ObjectSpace::WeakMap, but until recently that did not support Fixnum keys and I did not want to break DRb for older Ruby versions.Unfortunately, due to the lack of "reference queue" support in Ruby's Weakref, this implementation must do a full scan for dead references. This may be possible to improve, and would probably be resolved by using WeakMap.
We recently got another report pry-remote not working on JRuby. pry-remote uses DRb, and DRb still uses
ObjectSpace._id2ref
to simulate a weak map of objects. We would like to get this fixed and released so users can use pry-remote without enabling full ObjectSpace support.Notes:
Edit: Modified to use existing thread-safe
WeakMap
-based implementationWeakIdConv
by default. Without it being default, users of DRb will always end up using the_id2ref
version. We should simply eliminate that possibility.