Loading…
YJIT: Building a New JIT Compiler for CRuby
2023-10-18
- Source
- Shopify
- Published
- Added to Yomu
Summary
YJIT is a new just-in-time compiler being built inside CRuby to improve Ruby performance on modern hardware, where single-core speed gains are limited and energy efficiency matters. Unlike MJIT’s weaker results on large real-world applications, YJIT uses a data-driven focus on performance hotspots in Rails and Shopify Core and is based on Basic Block Versioning (BBV). After about one year, it reports speedups over the CRuby interpreter of 20% on railsbench, 39% on liquid template rendering, and 37% on activerecord, with near-peak performance after one benchmark iteration. YJIT passes CRuby’s roughly 30,000-test suite, Shopify Core and GitHub backend CI, while running on a small percentage of Shopify production servers; its team plans further CRuby changes and broader JIT coverage before and after its intended Ruby 3.1 integration.
Context
Ruby applications, including large Rails systems, need better performance as single-core processor improvements become less reliable and energy efficiency becomes more important. Although CRuby already includes MJIT, the source reports that it has been less successful at producing speedups on widely used applications such as Ruby on Rails.
Approach / What changed
YJIT is built inside CRuby and uses a data-driven focus on application hotspots, with Basic Block Versioning as its JIT architecture. It specializes dynamically typed code using type information, patches generated code at runtime, and gradually increases the share of execution handled by the JIT. The team also identifies potential CRuby changes involving object shapes, type tagging, constant caching, calling conventions, and C runtime methods.
Takeaways
- Basic Block Versioning lets YJIT specialize code using runtime type information and patch code as program behavior changes, while also supporting fast compilation and warmup.
- Embedding YJIT in CRuby requires the compiler to be written in C and to work with existing CRuby design decisions, but it enables almost 100% compatibility with Ruby code and packages.
- Only about 79% of railsbench instructions currently run under YJIT, leaving room for further gains and motivating changes that could also improve MJIT and the interpreter.