Foto von Joshua Fuller auf Unsplash
YJIT, the groundbreaking Just-In-Time compiler for Ruby, brings a significant performance boost to your applications. However, it's important to note that YJIT isn't enabled by default in ruby. Fear not, though – with a few straightforward steps, you can harness the power of YJIT on your MacOS system.
To begin, it's essential to rebuild Ruby with the proper configuration option. This involves using the --enable-yjit flag 1. Additionally, make sure you have rustc installed, as YJIT relies on it.
For users leveraging ruby-build, incorporating compile options is a breeze through environment variables 2. This allows for a seamless integration of YJIT into your Ruby environment, ensuring that your applications run with enhanced speed and efficiency.
$ brew install rust
$ RUBY_CONFIGURE_OPTS="--enable-yjit" rbenv install 3.3.0
$ rbenv shell 3.3.0
$ ruby --yjit -v
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT [arm64-darwin23]
$ ruby --yjit -e "p RubyVM::YJIT.enabled?"
true
$ ruby -e "RubyVM::YJIT.enable; p RubyVM::YJIT.enabled?"
true
These shell instructions provide a step-by-step guide to installing additionaly Rust, configuring YJIT, installing Ruby 3.3.0 with YJIT support, and checking if YJIT is enabled both from the command line and within a Ruby script.
Excitingly, with the release of Ruby 3.3.0, there are new possibilities for enabling YJIT directly from your code (run-time) 3. This empowers developers with greater flexibility and control, enabling them to fine-tune their Ruby setup according to their specific needs.
RubyVM::YJIT.enable if defined? RubyVM::YJIT.enable
In conclusion, elevating your Ruby experience with YJIT is a straightforward process that reaps substantial benefits. By following these steps and staying abreast of the latest Ruby updates, you can unlock a new level of performance for your applications.
SOCIAL SHARE CARD GENERATOR