Chapter 7. The Hash Table: The Workhorse of Ruby Internals

image with no caption

Ruby stores much of its own internal data in hash tables.

Experiment 5-1: How Long Does It Take to Save a New Instance Variable? showed us how in Ruby 1.9 and 2.0 the ivptr member of the RObject structure pointed to a simple array of instance variable values. We learned that adding a new value was usually very fast but that Ruby was somewhat slower while saving every third or fourth instance variable because it had to allocate a larger array.

Taking a broader look across Ruby’s C source code base, we find that this technique is unusual. Instead, Ruby often uses a data structure called a

Get Ruby Under a Microscope now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.