Why Hashes Will Be Faster in Ruby 2.0
summary
Ruby 2.0 replaces the old st_table entries for small maps by packing keys and values into the hash’s pointer array so stores keys and values inline and up to six key/value pairs avoid separate allocations. The change eliminates per-entry mallocs for small inserts (no malloc for small inserts), makes the first few inserts measurably faster, and causes a performance spike when switching back at the seventh entry. Measured results: microsecond lookups, ~6% faster loading 10,000 AR rows, ~2.5% faster on a Rails spec; an instrumentation run counted 409 hashes created for three lines.
AI-written summary · about
chapters (7)
- 0:00Introduction
- 0:44How Ruby hashes work
- 3:13Hash function and buckets
- 5:19Ruby 2.0 hash optimizations
- 7:22Performance impact
- 9:50Hashes in Rails internals
- 10:33Conclusion & Q&A








