Understanding Ruby's Method Cache
summary
Ruby 1.9 (YARV) compiles bytecode and installs an inline method cache so a method lookup done once can skip subsequent searches (call it 10 times, resolve once and save nine lookups), but the cache records a global state generation and most mutations (define_method, alias, changing constants, OpenStruct, autoload, refinements) bump that generation and invalidate everything. Profiling shows real sites repeatedly rebuild caches; James Golick prototypes James Golick's class‑contextual generations which limits invalidation to affected classes and measurably reduces wasted lookups.
AI-written summary · about
chapters (12)
- 0:00Start
- 3:59UNDERSTAND THE STACK
- 4:46WHAT IS METHOD RESOLUTION??
- 7:27Method Resolution in other languages Method Resolution in Ruby
- 7:55METHOD RESOLUTION IN RUBY 18
- 12:08METHOD RESOLUTION IN RUBY 19 (now with YARV!!)
- 22:11GENERATIONAL CACHE EXPIRATION
- 26:48WAIT, OPENSTRUCT INVALIDATES THE CACHE??
- 27:48REFINEMENTS
- 28:11MRI 1.9 method caching
- 28:24THE FUTURE
- 31:14CONCLUSIONS








