Improving CVAR performance in Ruby 3.1
summary
Announces a concrete change: Ruby 3.1 adds a class variable cache implemented as an inline cache stored on the topmost class that tracks global_cvar_state and skips repeated ancestor walks. Microbenchmarks show class variable access was 8.5× slower with 100 modules vs one, and railbench yields +42 RPS (about 6–7% faster, 615 → 657 RPS). The cache eliminates progressive slowdown and shows real-world speedup without code changes.
AI-written summary · about
chapters (9)
- 0:00Start
- 2:59Class Variables
- 3:40Class Instance Variables
- 6:45Class Variables and Instance Variables Are Stored in the Same Hash Table Structure in Ruby
- 8:58Benchmarks
- 15:50Railsbench
- 24:34Learn C
- 25:08How Ruby Is Designed
- 25:29Contributing to Ruby
related talks
33mUnderstanding Ruby's Method Cache
38mKeynote: The Case Of The Vanished Variable - A Ruby Mystery Story
45mFuture of RubyVM
46mRuby3: What's Missing?
51mOpening Day 3 Keynote
01h 15mSpeedupRails, Speedup Your Code
49mKeynote: Simple goal. Hard to accomplish
39mThe Case Of The Vanished Variable - A Ruby Mystery Story
