Anyone have any objections to disabling id2ref when ObjectSpace is not
enabled? Right now, in order to support this, we have to start tracking
a weak reference to the object whenever you request #object_id. Since
most people don't actually use that ID for anything other than a number,
we could conceivably just return the object's natural hash code if
id2ref wasn't enabled.
A quick scan of all my installed gems and libraries (including stdlib)
shows only a few uses, and we can probably lobby to fix them all:
lib/ruby/1.8/drb/drb.rb: ObjectSpace._id2ref(ref)
lib/ruby/1.9/drb/drb.rb: ObjectSpace._id2ref(ref)
lib/ruby/gems/1.8/gems/cursor-0.9/weakrefset.rb: o =
ObjectSpace._id2ref(id << 1)
lib/ruby/gems/1.8/gems/extlib-0.9.11/lib/extlib/hook.rb:
%(#{name}(#{args}) if self.class <=
ObjectSpace._id2ref(#{method_info[:from].object_id}))
lib/ruby/gems/1.8/gems/extlib-0.9.11/lib/extlib/hook.rb:
%(#{name}(#{args}) if self <=
ObjectSpace._id2ref(#{method_info[:from].object_id}))
lib/ruby/gems/1.8/gems/extlib-0.9.12/lib/extlib/hook.rb:
%(#{name}(#{args}) if self.class <=
ObjectSpace._id2ref(#{method_info[:from].object_id}))
lib/ruby/gems/1.8/gems/extlib-0.9.12/lib/extlib/hook.rb:
%(#{name}(#{args}) if self <=
ObjectSpace._id2ref(#{method_info[:from].object_id}))
Binary file lib/ruby/gems/1.8/gems/jruby-jars-1.3.0/lib/jruby.jar matches
lib/ruby/gems/1.8/gems/redparse-0.8.1/test/data/jbridge.rb: obj =
ObjectSpace._id2ref(key)
lib/ruby/gems/1.8/gems/redparse-0.8.1/test/test_redparse.rb:
define_method("test_id2ref_#{line}") {\\
lib/ruby/gems/1.8/gems/redparse-0.8.1/test/test_redparse.rb: o =
ObjectSpace._id2ref(obj.object_id);\\
lib/ruby/gems/1.8/gems/sequence-0.2.0/lib/sequence/functional.rb:
@hash.keys.map!{|id| ObjectSpace._id2ref(id)}
lib/ruby/gems/1.8/gems/sequence-0.2.0/lib/weakrefset.rb: case
(o2=ObjectSpace._id2ref id) #test id for validity
lib/ruby/gems/1.8/gems/sequence-0.2.0/lib/weakrefset.rb:
o = ObjectSpace._id2ref(id)
lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4/lib/sqlite3/driver/dl/driver.rb:
ObjectSpace._id2ref(n) rescue self.to_s
Here's a comparison of performance for Object#object_id with and without
ObjectSpace enabled (with id2ref disabled when ObjectSpace is disabled):
Before:
1M calls to Object#object_id 0.388000 0.000000 0.388000 ( 0.388000)
After:
1M calls to Object#object_id 0.286000 0.000000 0.286000 ( 0.286000)
Maybe it's not big enough to make a big difference, but it could add up.
- Charlie
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email