Implementing Core Set
summary
Ruby 4.0 replaces the stdlib Set with a new core implementation that uses a specialized table to drop the unnecessary hash value, yielding 33% memory savings for large sets and, after layout tweaks, about 28% smaller small-set footprints via embedded RTypedData optimizations. The add? (add predicate) path is rewritten in C to perform a single-table access under GVL, fixing the race and speeding it up. A small set C API is provided for extensions, subclass compatibility is preserved via a compatibility module, and the change is merged and working in practice.
AI-written summary · about
chapters (11)
- 0:00Core Set in Ruby 4.0
- 1:50Standard library Set issues
- 3:34Design goals for Core Set
- 7:22Reimplementing Set in C
- 10:50Thread safety in Core Set
- 15:42Garbage collection in Core Set
- 18:48Backwards compatibility
- 23:49Memory usage comparison
- 27:18Optimizing small Sets
- 28:43Core Set C API benefits
- 29:25Conclusion & Q&A








