Building a Better OpenStruct
summary
OpenStruct’s beautiful API hides a big cost: typical use runs 10–40× slower than an explicit class. Several fixes are explored: open_fast_struct avoids upfront method defs and runs ~4× faster but breaks code by returning truthy placeholder objects; a persistent openstruct defines methods on the class (≈5× faster, ~10% app speedup) and Ruby 2.3’s lazy-member change removes eager defs; a custom dynamic class hits ~8× faster than OpenStruct and narrows the gap to about 3× slower than a hand-written class.
AI-written summary · about
chapters (12)
- 0:00Introduction
- 1:47What is OpenStruct
- 5:19How OpenStruct works
- 10:11Why OpenStruct is slow
- 12:56Can we build better
- 13:17Round one OpenFastStruct
- 16:24OpenFastStruct problems
- 18:09Round two PersistentOpenStruct
- 22:01Round three OpenStruct improvements
- 23:05Round four DynamicClass
- 26:55Lessons learned
- 29:03Conclusion








