One Chapter From My Upcoming eBook: Ruby Under a Microscope

In my eBook I’ll explore Ruby internals
using an experimental approach.

Update: I just setup an email sign up form - if you give me your email address I'll send you one - count ’em - one email messsage when the eBook is finished.

You may have noticed I haven’t been blogging here for a while; instead I’ve been working on a new eBook about Ruby language internals. I find this topic fascinating! In fact many of my blog posts this year have been about how Ruby, JRuby and Rubinius actually work on the inside, “under the hood.” Instead of continuing to blog about it, I’ve decided to write an entire book which I plan to release this Fall. For now, I’m calling the book “Ruby Under a Microscope - Learning Ruby Internals Through Experiment.”

Today I’m excited to release a preview of one chapter of the eBook called “How Hashes Scale From One To One Million Elements.” Here’s a link to it:

 Ruby Under A Microscope

I might release another chapter in the next couple of months, or at least some excerpts from the book as blog posts. Ultimately I might charge some money for the finished version. To hear when the book is finished and available, just follow me on Twitter and/or subscribe to my RSS feed.

It was a blast to write and I hope it will be a relatively quick, fun read for you. I realize it’s very long - at 41 pages you’ll probably have to put it on your “read-it-later” list. But if you’re interested in the topic of Ruby internals I’d love to know what you think about either the chapter’s writing style or content. If you take the time to download and read it, here’s what you’ll find inside:

Table of Contents

  • Introduction
    • Why bother to study Ruby internals?
    • My approach in this book: theory and experiment
  • How Hashes Scale From One To One Million Elements
    • Theory: Hash tables in Ruby
    • Experiment 1: Retrieving a value from hashes of varying sizes
    • Theory: How hash tables expand to accommodate more values
    • Experiment 2: Inserting one new element into hashes of varying sizes
    • Theory: Why Hashes will be faster in Ruby 2.0
    • Experiment 3: Inserting one new element into hashes of varying sizes, for Ruby 2.0
    • Theory: How Ruby implements hash functions
    • Experiment 4: Using objects as keys in a hash
    • Theory: How Ruby saves order information in hashes
    • Experiment 5: Iterating over elements inserted into a Hash
    • Alternate theories: Hashes in JRuby
    • Alternate theories: Hashes in Rubinius
    • Conclusion
    • Appendix: Experiment Code

Many thanks a lot to everyone who read the “rough, rough draft” of this, and helped me refine my thinking and improve the text: Alex, Daniel, Rashmi, Peter, Mike, Jonathan and Amit.