Currently we define the flags field in RubyBasicObject as an int, probably because that was the simplest option at the time and we may have had memory alignment in mind, but in actuality the greated number of bits we currently use is about 10 (for module flags relating to includes and refinements.
Reducing the size of this field to a short would accommodate all of those values easily. Moving the additional flags for objects like Modules and Hashes could allow us to reduce the size of the field further to a byte. If we stop using flags to indicate nil and false, it could potentially be reduced to a single boolean for the object's frozen status, but future changes to Ruby (such as Ractor's "shareable" flag) would require adding back additional bits.
A reduction to short would immediately reduce the size of all objects by two bytes, and should be examine as a first pass at shrinking our objects. If feasible, moving more type-specific flags to booleans in those objects would allow reducing flags to a byte.
Memory savings could be enormous, similar to reducing small fixnum sizes in #9085.
Currently we define the
flagsfield inRubyBasicObjectas an int, probably because that was the simplest option at the time and we may have had memory alignment in mind, but in actuality the greated number of bits we currently use is about 10 (for module flags relating to includes and refinements.Reducing the size of this field to a short would accommodate all of those values easily. Moving the additional flags for objects like Modules and Hashes could allow us to reduce the size of the field further to a byte. If we stop using flags to indicate
nilandfalse, it could potentially be reduced to a single boolean for the object's frozen status, but future changes to Ruby (such as Ractor's "shareable" flag) would require adding back additional bits.A reduction to short would immediately reduce the size of all objects by two bytes, and should be examine as a first pass at shrinking our objects. If feasible, moving more type-specific flags to booleans in those objects would allow reducing flags to a byte.
Memory savings could be enormous, similar to reducing small fixnum sizes in #9085.