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 introduces two major features: Ruby Box and ZJIT, along with numerous improvements. These advancements aim to enhance Ruby's performance, security, and flexibility, offering new possibilities for developers and users alike.
Ruby Box: Isolation and Separation of Definitions
Ruby Box is a new experimental feature designed to provide separation between definitions. This feature is enabled by setting the environment variable RUBY_BOX=1. Developers can access Ruby Box through the Ruby::Box class. When definitions are loaded within a box, they are isolated to that specific box, preventing interference with other boxes.
The primary purpose of Ruby Box is to isolate and separate various aspects of Ruby, such as monkey patches, changes to global or class variables, class and module definitions, and loaded native or Ruby libraries. This isolation ensures that these changes do not affect other parts of the application or environment.
Ruby Box offers several use cases, including running test cases in isolation to protect other tests when monkey patches are used to override certain behaviors. It also enables web application developers to run multiple boxes in parallel, facilitating blue-green deployments on app servers within a single Ruby process. Additionally, Ruby Box can be used to evaluate dependency updates by comparing response differences using Ruby code.
Furthermore, Ruby Box serves as a low-level foundation for potential high-level "package" APIs, though such an API has not yet been designed. As an experimental feature, Ruby Box is expected to evolve and mature over time, offering even more robust isolation and separation capabilities.
ZJIT: The Next Generation Just-in-Time Compiler
ZJIT, a new just-in-time (JIT) compiler, is developed as the next generation of YJIT. To build Ruby with ZJIT support, users must have Rust 1.85.0 or newer and specify the --zjit option. The development of ZJIT is driven by a desire to raise Ruby's performance ceiling by increasing compilation unit size and utilizing SSA (Static Single Assignment) IR. Additionally, ZJIT is designed to encourage more outside contributions by adopting a more traditional compiler methodology.
While ZJIT is faster than the interpreter, it is not yet as fast 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. Future updates, such as Ruby 4.1 ZJIT, are expected to improve performance and stability.
Improved 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 ensures smoother communication between Ractors, enhancing overall performance and reliability.
Additionally, Ractor.shareable_p has been updated to provide better control and management of shared data between Ractors. These enhancements make Ractor more robust and efficient, enabling developers to leverage parallel processing more effectively.
In conclusion, Ruby 4.0.0 marks a significant milestone in Ruby's evolution, introducing innovative features like Ruby Box and ZJIT, along with improvements to Ractor. These advancements not only enhance Ruby's performance and security but also open new avenues for developers to build and maintain complex applications. As Ruby continues to evolve, the community can look forward to even more exciting developments in the future.




