ruby icon indicating copy to clipboard operation
ruby copied to clipboard

Shink RClass when it is known they can't be namespaced

Open byroot opened this issue 5 months ago • 2 comments

Even when namespaces are enabled, only a few core classes created during init will eventually be namespaced.

For these it's OK to allocate a 320B slot to hold the extra namespace stuff.

But for any class created post init, we know we'll never need the namespace and we can fit in a 160B slot.

byroot avatar Jun 18 '25 10:06 byroot

But for any class created post init, we know we'll never need the namespace and we can fit in a 160B slot.

I wonder if this will be true in the future because of singleton classes of pre-init namespaceable classes (they either need to also be made namespaceable, or we'd need to use namespacing to look up klass 😩) https://bugs.ruby-lang.org/issues/21343

jhawthorn avatar Jun 18 '25 23:06 jhawthorn

Good catch.

they either need to also be made namespaceable,

I think that is the way, but I can probably handle that. When creating a singleton class I can check if the attached object class is namespaceable.

byroot avatar Jun 19 '25 06:06 byroot

I made it so that metaclasses created from a namespaceable class are also namespaceable. (I didn't fix https://bugs.ruby-lang.org/issues/21343 though.)

byroot avatar Jun 20 '25 11:06 byroot