Ruby 4.0 Released With Ruby Box Isolation and New ZJIT Compiler

Ruby 4.0 is now available, introducing the experimental Ruby Box isolation feature, the new ZJIT compiler, and performance and concurrency improvements.

Ruby 4.0, a high-level, general-purpose programming language, has been released, introducing new isolation and compilation technologies alongside extensive performance, concurrency, and standard library updates.

The headline addition is Ruby Box, a new experimental mechanism designed to isolate definitions within a running Ruby process. When enabled via the RUBY_BOX=1 environment variable, Ruby Box allows classes, modules, global variables, monkey patches, and even loaded libraries to be confined to a specific box.

This enables use cases such as running test suites safely when monkey patches are involved, executing multiple versions of a web application side by side for blue-green deployments, or evaluating dependency upgrades in parallel by comparing runtime behavior.

Another major change is the introduction of ZJIT, a new experimental just-in-time compiler that succeeded YJIT. ZJIT is a method-based JIT built with larger compilation units and an SSA-based intermediate representation, to raise Ruby’s long-term performance ceiling and make the compiler more approachable for external contributors.

ZJIT requires Rust 1.85 or newer to build and can be enabled with the –zjit option or at runtime. In Ruby 4.0, ZJIT already outperforms the interpreter, though it still lags behind YJIT. The Ruby core team advises against production use and recommends experimentation, with the stated goal of making ZJIT production-ready and faster than YJIT in Ruby 4.1.

Moreover, Ruby 4.0 introduces the new Ractor::Port class to provide a clearer and more robust communication mechanism between Ractors, replacing earlier APIs such as Ractor.yield and Ractor#take, which have now been removed. Ractors also benefit from reduced global lock contention, less shared internal state, and improved CPU cache behavior, all contributing to better parallel performance.

At the language level, Ruby 4.0 includes several notable changes. Logical operators at the beginning of a line now continue the previous line, improving readability in multiline conditionals. The handling of *nil has been aligned with other splat behaviors, and error reporting for argument count mismatches has been enhanced with clearer backtraces and contextual code snippets.

Core classes and modules see a wide range of improvements. Arrays gain more efficient search methods, Enumerator gains better size awareness, File::Stat exposes file birth time on Linux when supported by the kernel and filesystem, and Set has been promoted from the standard library into a core class with a simplified inspect output.

Pathname is now a core class as well, and Unicode support has been updated to version 17.0, including Emoji 17.0. Numerous APIs across IO, Fiber, Thread, Socket, and Kernel have been refined, extended, or cleaned up by removing long-deprecated behaviors.

The standard library has also been reorganized. Several bundled gems have been promoted from default status, others updated to newer major versions, and some components removed or split out, such as the CGI library, which is no longer provided in full by default.

On the implementation side, Ruby 4.0 delivers broad performance improvements. Object creation is faster, especially when keyword arguments are involved. Garbage collection is more efficient across multiple dimensions, instance variable access has been optimized internally, and locking has been reduced in many hot paths.

Finally, Ruby 4.0 also introduces compatibility changes that developers need to be aware of. Several deprecated APIs have been removed, including legacy process-creation behaviors and older Ractor methods, and some C APIs have been deprecated or adjusted to improve safety and correctness. Windows support now requires Visual Studio 2015 or newer.

For more information, see the announcement.

Bobby Borisov

Bobby Borisov

Bobby, an editor-in-chief at Linuxiac, is a Linux professional with over 20 years of experience. With a strong focus on Linux and open-source software, he has worked as a Senior Linux System Administrator, Software Developer, and DevOps Engineer for small and large multinational companies.

Leave a Reply

Your email address will not be published. Required fields are marked *