Building a Better OpenStruct
summary
Shows concrete fixes and fast alternatives: Ruby's OpenStruct is 10–40× slower than an explicit class and global method cache issues are fixed in Ruby 2.1. It demos profiling with stackprof and benchmark-ips and three implementations: OpenFastStruct (about 4× faster but changes nil semantics), PersistantOpenStruct (roughly 5× faster, defines methods once per class), and DynamicClass (about 8× faster than OpenStruct, 40% faster than PersistantOpenStruct, still ~3× slower than a hand‑written class). Benchmarks and code are available and the DynamicClass approach works.
AI-written summary · about
chapters (9)
- 0:00Start
- 1:05OPENSTRUCT IS RUBY'S JAVASCRIPT OBJECT
- 5:13CONFIGURATION OBJECT
- 5:49TEST DOUBLE
- 7:38HOW DOES IT WORKS
- 11:20OPENSTRUCT IS SLOW
- 12:47METHOD LOOKUP IN RUBY
- 15:12HIERARCHICAL METHOD CACHE
- 32:41Dynamic Class








