Enable and check YJIT in Ruby 3.2

There are a couple of ways to enable YJIT for your Ruby application and also a couple of ways to check if YJIT is enabled.

Usually, you could activate YJIT using ruby --enable-yjit -v. However, in our (mostly) container-based world, this does not do much. You can set an environment variable for those cases named RUBY_YJIT_ENABLE and set it to 1. This is an instruction you could include in your Dockerfile.

ENV RUBY_YJIT_ENABLE=1

To check if YJIT is enabled, there are two ways.

First, ask the Ruby version for your system. It will tell you if YJIT is enabled.

Non-YJIT:

$ ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-darwin22]

YJIT enabled:

$ ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) +YJIT [x86_64-linux-musl]

Another way is to ask from within an irb session.

Non-YJIT:

$ irb
irb(main):001:0> RubyVM::YJIT.enabled?
=> false

YJIT:

$ irb
irb(main):001:0> RubyVM::YJIT.enabled?
=> true