RUBYLAND
Read post

Shrinking Ruby Hashes

A deep dive into Ruby Hash memory usage across versions, tracing the evolution from Ruby 2.3 to 4.1. Covers the history of ar_table (array table), Variable Width Allocation, and the lower-byte hashcode optimization. The author explains current work to shrink st_table by 8 bytes via struct packing (moving entries_start into a 1-byte field), enabling mutable hashes to fit in 64B GC slots. Also covers frozen hash optimization already merged, and an in-progress patch for dynamic ar_table sizes that could bring small hash memory usage much closer to theoretical minimums. Includes practical advice: prefer Struct or plain Ruby objects over Hash when structure is known.

    #ruby
Yesterday•29m read time•From byroot.github.io
Post cover image
Table of contents
Measuring Memory UsageOpen AddressingArray TablesLower Byte HashcodeVariable Width AllocationGoing SmallerKnock-On EffectsData LocalityImmutabilityStruct PackingDynamic AR Table SizesTakeaways
99 Impressions
RUBYLAND's image
RUBYLAND

The RubyLA blog offers insights, tutorials, and community updates for Ruby developers in Los Angeles...

465 Followers

•

5K Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard