Exploring Internal Ruby Through C Extensions
summary
Reimplements Ruby Hash as a CRuby C extension, a thin C++ wrapper over abseil/ordermap, a pure C++ version and a Ruby-array-backed version, then benchmarks them on an 8‑vCPU Debian VM (Ruby 2.5.1, gcc 6.3.0). Results: pure C++ is fastest, CRuby’s native Hash matches C++ performance, the C++ wrapper is ~20–30% slower and the pure-Ruby reimplementation is ~2.5× slower. Memory measured with Valgrind. Covers VALUE internals, rb_data_type_t, custom mark/free hooks and how mark‑and‑sweep GC costs explain the wrapper’s overhead.
AI-written summary · about
chapters (16)
- 0:00Introduction and speaker intro
- 1:04What are C extensions
- 2:31Hello World in C extension
- 3:33Reimplementing Ruby Hash in C
- 7:11Ruby’s memory management
- 10:26Garbage collection in Ruby
- 13:00Memory lifecycle in C extensions
- 15:15Ruby and C++ code comparison
- 18:13How Ruby values work
- 20:06Benchmark setup and results
- 24:14Why C++ wrapper was slower
- 26:30Benchmark pitfalls and string handling
- 27:37Key takeaways and best practices
- 30:08When to use C extensions
- 31:40Recommended resources
- 33:10Q&A session








