Strings! Interpolation, Optimisation & Bugs
summary
A performance regression in string interpolation traces to the VM instruction concat strings and a seven‑year‑old heuristic min_pralo_size = 48 that chose to reuse the first fragment, causing embedded strings to become extended and slowing things. Benchmarking shows removing the heuristic alone regresses ~9%, but replacing the public encoding copy with an internal fast encoding copy and always preallocating fixes the misallocation, doubles some interpolation cases and ships in Ruby 3.3 under variable width allocation.
AI-written summary · about
chapters (13)
- 0:00Introduction and speaker intro
- 1:09Background on variable width allocation
- 4:45String interpolation bug discovery
- 7:57Investigating the interpolation code
- 10:01Analyzing the concat_strings instruction
- 12:31Diving into RB_string_concat_literals
- 15:00Tracing the optimization’s origin
- 17:48Performance impact of string resurrection
- 19:35Fixing the encoding safety checks
- 21:21Refactoring for cleaner code
- 22:23Benchmarking and Ruby 3.3 results
- 23:05Key takeaways and lessons learned
- 25:10Closing thanks and call to contribute
related talks
39mPointers for Eliminating Heaps of Memory
27mOptimizing Ruby's Memory Layout
34mHow to optimize Ruby internal.
24mLies, Damned Lies, and Substrings
19mThe Harvey Dent Dilemma: Ruby's White Knight Rises (or Falls)
46mRuby Memory Management Hacks
38mFinding a needle in the haystack - Debugging performance issues
28mLooking Into Peephole Optimizations
