How Are Method Calls Formed?
summary
Claims a polymorphic inline caches patch that adds ~186 lines to MRI, instruments bytecode with tracepoints and Ruby vmstat, and measures against a large Rails app with 4 million calls. Results show most call sites are monomorphic so speedups are negligible; one hotspot sees 16,000 types (eventmachine/thin causing singleton classes). Fixes include changing arrays to sets to restore monomorphism. Conclusion: optimization is workload specific and often not worth landing.
AI-written summary · about
chapters (25)
- 0:00Start
- 9:00Methods
- 11:54Call Site Example
- 14:39Stack Based
- 16:05High Level
- 16:22Method Call Byte Code
- 16:50Method Byte Code
- 19:22Finding the Method
- 21:46Benchmark Bytecode
- 23:42Bytecode Verification
- 24:15Call Sites (cache locations)
- 24:44Cache key / value
- 26:36Breaking the cache
- 28:24Runtime Breakage
- 29:20What is this an instance of?
- 30:40Singleton Class Access
- 31:14Cache Misses
- 32:17Polymorphic Test
- 35:20Patch
- 35:52Mission Accomplished!
- 37:37Method Cache logging
- 37:52Logging Test
- 38:39Output
- 44:23Performance
- 45:08Behavior
related talks
49mHow are Method Calls Formed?
28mWho You Gonna Call: Analyzing the Run-time Call-Site Behavior of Ruby Applications
30mFast Metaprogramming with Truffle
41mPerformance Improvement of Ruby 2.7 JIT in Real World
37mWhat’s happening in your Rails app? Introduction to Introspection features of Ruby
42mThe Mechanics of Ruby
46mRuby Memory Management Hacks
34mHow to optimize Ruby internal.
