Try Out YJIT for Faster Rubying

Shopify is building a new JIT implementation on top of CRuby. This post walks through how to build CRuby and all about building YJIT.

Noah Gibbs
8 min readintermediate
--
View Original

Overview

The article discusses YJIT, a new Just-In-Time Compiler built on top of CRuby, aimed at improving Ruby performance. It highlights early benchmarks showing speed improvements and provides guidance on how to install and run YJIT, along with insights into its current stability and production readiness.

What You'll Learn

1

How to install YJIT in CRuby

2

How to run benchmarks to compare YJIT performance

3

Why YJIT may not always deliver real-world speedups

4

When to enable YJIT for testing in your applications

Prerequisites & Requirements

  • Autoconf, make, OpenSSL, and GCC or Clang
  • Basic understanding of Ruby and its environment(optional)

Key Questions Answered

What performance improvements can YJIT provide?
YJIT can speed up a simple 'hello, world' Rails benchmark by 20% or more. Early results show that it runs reliably on Shopify's full suite of unit tests and has been tested successfully on GitHub's tests as well.
How can I check if YJIT is installed?
You can check if YJIT is installed by running the command 'ruby --enable-yjit -v'. If YJIT is enabled, you will see a confirmation message. If not, you may be using a different Ruby version.
Is YJIT ready for production use?
YJIT has shown some speed improvements in benchmarks and unit tests, achieving around 6% speedup in production code. However, it is still in progress and not yet widely deployed across all services.
What are the prerequisites for building CRuby with YJIT?
To build CRuby with YJIT, you need tools like Autoconf, make, OpenSSL, and a C compiler such as GCC or Clang. On Mac, you can use Homebrew to install these tools.

Key Statistics & Figures

Speed improvement on Rails benchmark
20%
This improvement was observed on a simple 'hello, world' Rails benchmark.
Production speedup achieved
6%
This speedup was noted during tests on Shopify's production code.

Technologies & Tools

Backend
Cruby
YJIT is implemented as a Just-In-Time Compiler on top of CRuby.
Tools
Openssl
Required for building CRuby with YJIT.
Tools
Gcc
Used as a C compiler for building CRuby with YJIT.

Key Actionable Insights

1
Consider testing YJIT on your existing Ruby applications to evaluate performance gains.
Running benchmarks with YJIT enabled can provide insights into potential speed improvements for your specific workload, especially if you're using Rails.
2
Stay updated on YJIT's development and community feedback.
As YJIT is still evolving, following its progress and community discussions can help you make informed decisions about adopting it in production.
3
Enable runtime statistics to gather detailed performance data from YJIT.
Compiling YJIT with debugging options allows you to analyze its performance more thoroughly, which can be crucial for optimizing your applications.

Common Pitfalls

1
Using the wrong version of Autoconf can lead to build failures.
It's important to use Autoconf version 2.69, as version 2.71 has been reported to cause issues with Ruby.
2
Not enabling YJIT by default can lead to confusion about performance.
YJIT is not enabled by default, so developers must remember to enable it explicitly to see its benefits.

Related Concepts

Just-in-time Compilation
Ruby Performance Optimization
Benchmarking Techniques