Ruby 3.2’s YJIT is Production-Ready
YJIT, Shopify's JIT compiler for CRuby, became production-ready in Ruby 3.2 after a port from C99 to Rust and a cut in memory overhead to about a third of Ruby 3.1 levels. The memory savings came from smaller metadata, garbage collection of unused machine code and lazily allocated code pages. YJIT now runs about 38% faster than the 3.2 interpreter on railsbench and supports ARM64. Deployed across Shopify's entire Storefront Renderer, it delivers 5–10% end-to-end request speedups, and its fast compilation suits continuous deployment. Planned work targets memory footprint, faster method calls via a new calling convention and inlining, and a register allocator.
Related posts
- Try Out YJIT for Faster Rubying
Shopify Engineering mediumAdeptYJIT, Shopify's just-in-time compiler built into CRuby and slated for Ruby 3.1, compiles frequently used Ruby code to native machine code, speeding up a simple Rails benchmark by 20% or more and a real Shopify web service by about 6% on canary traffic. Building it is the same as building CRuby from source: autoconf 2.69, OpenSSL 1.1 and a C toolchain, then enabling it with --enable-yjit or RUBY_YJIT_ENABLE=1. Compiling with YJIT_STATS or RUBY_DEBUG exposes detailed runtime statistics such as the share of instructions YJIT executed, generated code size and ISEQs compiled. YJIT passes Shopify's and GitHub's unit test suites but is still early, so the team asks users to report crashes and performance results.
- YJIT: Building a New JIT Compiler for CRuby
Shopify Engineering easyNoviceYJIT is a new JIT compiler built inside CRuby by Shopify and GitHub engineers, based on Basic Block Versioning, and aimed at real-world workloads like Rails where the GCC-based MJIT has struggled. After about a year it delivers speedups over the interpreter of 20% on railsbench, 39% on liquid template rendering and 37% on activerecord, with near-peak performance after one iteration. It passes CRuby's ~30,000 tests and the CI suites of Shopify Core and GitHub, and is slated to merge into Ruby 3.1. Only about 79% of railsbench instructions currently run in YJIT, and planned CRuby changes include object shapes, cheaper type tagging, finer-grained constant caching, a lighter calling convention, and rewriting C runtime methods in Ruby to enable inlining.
- Our Experience Porting the YJIT Ruby Compiler to Rust
Shopify Engineering mediumAdeptShopify's YJIT team ported the CRuby JIT compiler from about 11,000 lines of C99 to Rust because C's lack of modules, generics, containers and safe macros made a growing compiler hard to manage. They translated it function by function without major redesign. Pattern matching, hygienic macros, Cargo features and string handling were clear wins. The pain points were concrete: offline builds without crates.io (they fell back to invoking rustc directly), bindgen silently failing on a large internal C API, verbose manual integer casting that discourages compact data layouts, and a cyclic control-flow graph where Rc/RefCell broke down, forcing manual memory management.
- When is JIT Faster Than A Compiler?
Shopify Engineering easyNoviceJITs can beat ahead-of-time compilers for highly dynamic languages like Ruby because they can compile code under speculative assumptions, such as that Integer#+ hasn't been redefined, and throw that code away (de-optimize) when an assumption breaks. An AOT compiler must emit code that stays correct no matter what the program does later. An interpreter must constantly re-check whether anything changed. Both end up conservative and slow. YJIT in CRuby uses this speculate-and-invalidate approach, enabled with --yjit, and is expected to be production-ready for some uses in Ruby 3.2.
- Year in Review 2022: Tenderlove's Ruby and Rails Reflections and Predictions
Shopify Engineering easyNoviceRuby's 2022 highlights include YJIT's rewrite in Rust and its new ARM support, so `ruby --yjit` now runs on Apple Silicon development machines as well as production. Variable Width Allocation became the default: Ruby learns when a class needs more instance-variable slots than the fixed 40-byte object provides and allocates later instances from wider slot pools, which improves cache locality. Ruby 3.2's Object Shapes give inline caches a class-independent key based on which instance variables were set and in what order, which helps deep hierarchies like Active Record. On the tooling side, Ruby LSP brings editor features to Ruby, and Error Highlight's column-level error pointers now appear on Rails error pages, part of a broader push for developer ergonomics in 2023.