ObjectSpace
Ruby’s ObjectSpace is one of those things like Thread.critical that
is used by critical things, but is a bear to implement and therefore
aggravates Ruby implementors quite a lot.
So far as I can tell, there are three main uses for it in the wild:
- Find all descendants of a class.
- Find all instances of a class.
- Weak/”serializable” references (via
ObjectSpace._id2ref)
Are there any others? As with Thread.critical, it is facility perhaps
too general for its own good. If we can find other ways to address those
needs which is is actually used to address, we can reasonably think about
removing it.
Update: the issue is specifically that ObjectSpace is impossible to
implement efficiently when you don’t control the GC. As a consequence,
JRuby (for example) provides an -O option to turn it off for
performance. In the case of Thread.critical, it’s actually impossible
to implement reliably on the JVM or with concurrent POSIX threads.
So, it’s a question of either making such features of the language optional (on a de-facto basis if nothing else), or finding replacements which we can guarantee will be available on all Ruby implementations.
I much prefer the latter option, keeping portability of Ruby programs across different implementations.