The Ruby programming language continues its tradition of releasing major updates at Christmas time by announcing the release of Ruby 4.0.0, which introduces two new experimental features: an isolation mechanism known as the Ruby Box and a next-generation ZJIT compiler.
The biggest architectural change coming with version 4.0 is definitely Ruby Box. This new experimental feature has strict separation of the definitions loaded into the block. If you've ever dealt with complex dependency problems or had a rogue patch monkey mess up your global environment, you know how important isolation can be. Definitions loaded inside Ruby Box are isolated from other blocks, meaning they can separate changes to global or class variables, class definitions, and even loaded native libraries.
The Ruby team suggests using blocks to run test cases where you might need monkey patches, without worrying about those changes leaking and affecting other tests. You can also use this feature as the basis for implementing a blue-green deployment strategy on your application server by running parallel web application blocks in a single Ruby process. This is a powerful low-level API, and I fully expect high-level package management tools to make heavy use of it in the future.
In terms of performance, the developers are already moving beyond YJIT with the introduction of ZJIT, an entirely new just-in-time compiler. ZJIT is designed as the next step forward in Ruby performance, aiming for a much higher performance ceiling through the use of things like SSA IR and larger compilation units. The team is also trying to make ZJIT a more traditional method compiler, which should encourage more input from outside optimization experts.
At the moment, ZJIT is still in the experimental stage. Although it is noticeably faster than the standard Ruby interpreter, it has not yet caught up with YJIT. I'd say the biggest issue is that you shouldn't rely on it for workloads just yet, but you can certainly experiment with it now if you have Rust 1.85.0 or later installed to build it. We'll have to wait for Ruby 4.1 to see if ZJIT really becomes the performance champion the team is aiming for.
In addition to new experimental features, we are seeing significant improvements in the stability and performance of Ractor, Ruby's parallel execution engine. Ractor was introduced as experimental in Ruby 3.0, and the team is working to remove this tag next year. The update includes major internal optimizations aimed at improving concurrency. Ractors now share less internal data, reducing CPU cache contention when running multiple threads simultaneously.
The Ractor synchronization engine has also been updated with the introduction of a new class called Ractor::Port. This class provides explicit methods such as receive And send for communication between Ractors. This addition removes older, less intuitive methods such as Ractor.yield And Ractor#take. Developers also get new techniques such as Ractor#join And Ractor#valuewhich reflect the familiar behavior of threads when waiting for Ractor to complete. New Ractor.shareable_proc It also greatly simplifies the transfer of logic between parallel execution units.
Ruby 4.0 also contains several improvements to the core language and built-in classes. For example, the language now supports Boolean binary operators such as && or || to continue the previous line if they appear at the beginning of a new line, similar to how the running dot operator works.
One feature I really like is the improvement ErrorHighlight. When ArgumentError occurs, the debugger now displays code snippets for both the method call and its definition. This feature is very useful for debugging, allowing you to instantly see where the wrong number of arguments were passed and where a method was defined, all in one easy-to-understand snippet.
Core classes also received a privacy-focused update. Kernel#inspect the method now checks for the presence of a private method named instance_variables_to_inspect. In addition, two commonly used components, Pathname And Setare being promoted from default gems to core classes.
It's a big update, but that's what you should expect from version 4.0; You can get the latest tarball or zip from the official website today.
Source: Ruby





