Hi Dmitry,

> It already works, but it's considerably slower than MRI because I'm
> using ObjectSpace.each_object there, for any operation. It's quite fast
> on MRI, so it seemed appropriate.

In general terms, we don't consider this actually to be appropriate. The 
biggest problem is that it basically entails having to do the same work as a 
full GC cycle, to walk all of the objects in the system.

> Is there a faster way to do the following things on Rubinius?
> 
> 1) Enumerate all modules (or all classes) loaded in the current
> environment.

We could add special case logic here like JRuby has. They basically treat 
each_object with Class or Module specially so it doesn't suffer from the 
problem of having to track way more runtime information or depend on GC 
infrastructure to track this. It might be useful to add similar mechanisms to 
Rubinius.

> 2) Enumerate all descendants of a given class. I've looked at
> ActiveSupport::DescendantsTracker, and it kinda works, but ideally I
> would like to be able to enumerate even the core classes, that are
> loaded during IRB startup. It doesn't seem to help with that.

This information is actually already available in Rubinius, but there is 
currently not a standardized API across Ruby implementations for this. We 
already track this information for method cache invalidation purposes. Every 
Module (and thus also Class) has an instance variable name 
@hierarchy_subclasses. This contains an Array of Weakref objects pointing to 
inheriting classes. You could walk this recursively to obtain all the children.

Please note however that this is currently an internal API and could change in 
the future. We could look at providing an API for this, but the biggest problem 
is that we can't just use something that would collide with something like 
DescendantsTracker.

-- 
Regards,

Dirkjan Bussink

-- 
-- 
--- !ruby/object:MailingList
name: rubinius-dev
view: http://groups.google.com/group/rubinius-dev?hl=en
post: [email protected]
unsubscribe: [email protected]
--- 
You received this message because you are subscribed to the Google Groups 
"rubinius-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to