0

I want to enable YJIT on a Rails project. I have moved the codebase to Ruby 3.2 and am trying to enable YJIT by setting the RUBY_YJIT_ENABLE to 1 in a canary release receiving 50% of the traffic so that I can see the two side by side. In the canary release, with the env var set, when I SSH into production I get:

~/app $ env | grep YJIT
RUBY_YJIT_ENABLE=1
~/app $ ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) +YJIT [x86_64-linux-musl]

Unfortunately, I don't see the performance benefits that others are reporting. Below you can see two graphs, one for the memory usage and one the average request time for requests. In both graphs, blue is the canary release with YJIT enabled and yellow is the one with YJIT disabled (both are ruby 3.2).

enter image description here

enter image description here

That's why I wanted to ask if there is anything else that I need to do. Does the ruby -v output mean that YJIT is enabled?

Is the rustc a runtime dependency for YJIT to work? Because my current setup doesn't include it.

Markos Fragkakis
  • 7,499
  • 18
  • 65
  • 103

1 Answers1

1

It's my understanding that the +YJIT indicates that YJIT is enabled. I could not find any official documentation to reference but it looks like rustc is a compile time dependency for Ruby 3.2 but not a runtime dependency. I use the docker image ruby:3.2.2-alpine3.18 which is only 33MB because it compiles Ruby using C and YJIT using Rust. Then it only copies over the Ruby binaries and dependencies which includes YJIT. You can verify that YJIT is actually running with the following commands.

docker run -it ruby:3.2.2-alpine3.18 /bin/sh
RUBYOPT=--yjit irb
RubyVM::YJIT.enabled?
=> true
RubyVM::YJIT.runtime_stats
=>
{:inline_code_size=>337228,
 :outlined_code_size=>337004,
 :freed_page_count=>0,
 :freed_code_size=>0,
 :live_page_count=>42,
 :code_gc_count=>0,
 :code_region_size=>684032,
 :object_shape_count=>706}

Also, looking at your graphs (although they are missing the legend so I'm assuming the light blue is the canary using YJIT), the RAM usage is higher which is the expected tradeoff (RAM vs CPU) and while not always faster the response time looks like it's often a little faster.

Dave Morehouse
  • 241
  • 1
  • 7