Making .is_a? Fast
summary
Claim: Ruby's is_a? family used to cost 2–4% of runtime in real apps and scan long ancestor chains (one model had 305 ancestors, the repo had 92,000 classes). Using stackprof rbspy Linux perf and Railsbench, author implements and benchmarks alternatives, ships a constant time depth-table lookup in C with de‑duplication to cut memory (6.5MB → ~1MB) and lands the change and YJIT assembly in Ruby 3.2, giving a clear, measured win.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 3:37Profiling .is_a? impact
- 7:58How .is_a? checks ancestry
- 11:55Optimizing .is_a? challenges
- 14:09Hash-based ancestor lookup
- 17:23Skipping module ancestors
- 19:31Array-based linear scan
- 21:43Shared ancestor arrays insight
- 24:09Memory optimization for ancestors
- 25:36C implementation results
- 26:39Conclusion








