~/talk

Implementing Core Set

Talkat RubyKaigi 2026 · 2026-04-22..04-24· [ruby]
slides:none on file

Ruby 4.0 replaces the stdlib Set with a native SET_TABLE-backed implementation that removes per-entry hash values and yields about a 33% memory reduction for large sets. The add?/add method becomes a single C table access under the GVL, fixing a race and improving speed; insertion uses set_insert_WB and RB_OBJECT_WRITTEN write-barriers to keep GC safe. Work copies ~1/3 of hash table code and rewrites the other 2/3 as C methods; compatibility is preserved via a set_subclass_compatible module and an alternate core_set subclass for users who need the faster, non-compat mode.

AI-written summary · about

  1. 0:00Introduction
  2. 1:06Set history and issues
  3. 3:31New set implementation
  4. 8:04Reimplementing set methods
  5. 11:52Set initialization in C
  6. 14:17Memory optimization
  7. 16:01Garbage collection support
  8. 17:03Thread safety fixes
  9. 19:08String handling
  10. 20:31Set table usage elsewhere
  11. 21:13Set subclass compatibility
  12. 23:58Memory usage for small sets
  13. 26:47Memory optimization challenges
  14. 28:11Conclusion and book
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.