The release of Ruby 4.0.0, a dynamic object-oriented programming language focused on high efficiency in program development and incorporating the best features of Perl, Java, Python, Smalltalk, Eiffel, Ada and Lisp. The project code is distributed under the BSD (“2-clause BSDL”) and “Ruby” licenses, which refers to the latest version of the GPL license and is compatible with GPLv3.
General improvements:
- Includes a new JIT compiler ZJIT, positioned as the next generation of Ruby JIT. The YJIT JIT compiler continues to be used by default, and ZJIT is enabled as an option (activated by the “–zjit” flag). Like YJIT, the new JIT compiler is written in Rust by a team of developers from Shopify as part of an initiative to increase the performance of Ruby programs that use the Rails framework and call a lot of methods. At the current stage of development, ZJIT is faster than the interpreter, but still lags behind YJIT in performance (it is expected that in Ruby 4.1 ZJIT will be stabilized and will outperform YJIT).
Unlike YJIT, the new JIT compiler translates the bytecode of the YARV virtual machine not into a low-level intermediate representation close to machine code, but into a high-level intermediate representation SSA (Static Single Assignment), which allows you to perform additional optimization phases and optimize large blocks of code, not just current operations. To attract new participants to the work, ZJIT implements the classic JIT architecture, which uses the historical type data accumulated by the interpreter, instead of the complicated technique of versioning basic blocks (LBBV – Lazy Basic Block Versioning) used in YJIT.
- An experimental class Ruby::Box has been added with the implementation of an isolation mechanism that allows you to separate the execution of classes, modules and monkey patches (substituted methods and class attributes). Using Ruby::Box, you can also separate the execution of application code from Ruby libraries, provide test isolation, and organize parallel execution