Ruby 4.0.0 Released
We are pleased to announce the release of Ruby 4.0.0. Ruby 4.0 introduces “Ruby Box” and “ZJIT”, and adds many improvements. Ruby Box Ruby Box is a new (experimental) feature to provide separation about definitions. Ruby Box is enabled when an environment variable RUBY_BOX=1 is specified. The class is Ruby::Box . Definitions loaded in a box are isolated in the box. Ruby Box can isolate/separate monkey patches, changes of global/class variables, class/module definitions, and loaded native/ruby libraries from other boxes. Expected use cases are: Run test cases in box to protect other tests when the test case uses monkey patches to override something Run web app boxes in parallel to execute blue-green deployment on an app server in a Ruby process Run web app boxes in parallel to evaluate dependency updates for a certain period of time by checking response diff using Ruby code Used as the foundation (low-level) API to implement kind of “package” (high-level) API (it is not designed yet) For the detail of “Ruby Box”, see Ruby::Box . [ Feature #21311 ] [ Misc #21385 ] ZJIT ZJIT is a new just-in-time (JIT) compiler, which is developed as the next generation of YJIT. You need Rust 1.85.0 or newer to build Ruby with ZJIT support, and ZJIT is enabled when --zjit is specified. We’re building a new compiler for Ruby because we want to both raise the performance ceiling (bigger compilation unit size and SSA IR) and encourage more outside contribution (by becoming a more traditional method

Ruby 4.0.0 Released: Introducing Ruby Box, ZJIT, and Enhanced Ractor
Ruby developers can celebrate the release of Ruby 4.0.0, which brings significant enhancements and new features to the language. This version introduces two major innovations: "Ruby Box" and "ZJIT," along with numerous improvements to existing components like Ractor.
Ruby Box: Isolation and Separation of Definitions
Ruby Box is a new experimental feature designed to provide separation between definitions. It aims to isolate various aspects such as monkey patches, changes to global or class variables, class/module definitions, and loaded native or Ruby libraries. This feature is particularly useful for scenarios where isolation is critical, such as running test cases that involve monkey patches, executing blue-green deployments for web applications, or evaluating dependency updates.
To enable Ruby Box, users must set the environment variable RUBY_BOX=1. The class associated with this feature is named Ruby::Box. Definitions loaded within a box are kept isolated, ensuring that they do not interfere with other boxes. While the high-level API for implementing "package" functionality is not yet designed, Ruby Box serves as a low-level foundation that can be used to build such features in the future.
ZJIT: The Next-Generation Just-in-Time Compiler
ZJIT, a new just-in-time (JIT) compiler, has been developed as the next generation of YJIT. To build Ruby with ZJIT support, users need Rust 1.85.0 or newer, and ZJIT is enabled by specifying the --zjit option. The Ruby team is building this new compiler to raise the performance ceiling by utilizing bigger compilation unit sizes and SSA (Static Single Assignment) IR. Additionally, the team hopes to encourage more outside contributions by adopting a more traditional compiler method.
While ZJIT is faster than the interpreter, it is not yet as performant as YJIT. Developers are encouraged to experiment with ZJIT, but it is advised to avoid deploying it in production environments until further optimizations are made. Stay tuned for Ruby 4.1, which will likely bring more improvements to ZJIT.
Improvements to Ractor: Enhanced Parallel Execution
Ractor, Ruby's parallel execution mechanism, has received several enhancements in Ruby 4.0.0. A new class, Ractor::Port, has been introduced to address issues related to message sending and receiving. This improvement is expected to provide better stability and performance when dealing with parallel tasks.
Additionally, Ractor.shareable_p has been updated to facilitate sharing data between Ractors more efficiently. These enhancements are designed to make Ractor a more robust and reliable tool for developers working with parallel execution in Ruby applications.
In conclusion, Ruby 4.0.0 represents a significant milestone in the evolution of the Ruby programming language. With the introduction of Ruby Box and ZJIT, along with improvements to Ractor, this release offers developers powerful new tools and enhanced performance. As always, the Ruby community continues to innovate and push the boundaries of what is possible with the language.




