YJIT Compiler for Ruby
Optimizing Ruby Lazy Initialization in TruffleRuby with Deoptimization - Shopify

Optimizing Ruby Lazy Initialization in TruffleRuby with Deoptimization - Shopify

3/31/2020

What this post added

Introduced an optimization for Ruby's lazy initialization (`||=`) operator in TruffleRuby. This optimization leverages deoptimization by replacing the standard `OrNode` with an `OrLazyValueDefinedNode`. The new node counts the executions of the right-hand side of the `||=` operator and triggers deoptimization if it's executed less than twice. This reduces the amount of machine code generated and speeds up compilation for this common idiom, improving performance and memory usage.

Read the original post ↗