Ruby 3.4: Prism becomes the new standard parser for performance optimization
For the Ruby programming language, the update to version 3.4 brings a new keyword for block parameters with "it" and Prism as a new standard parser.
The development team behind the dynamic and object-oriented programming language Ruby has released version 3.4. The update contains a number of new features, including a new it
keyword, Prism as the default parser and new functions for YJIT.
it keyword and Prism
Ruby 3.4 includes the it
keyword, which is intended to make it easier to reference block parameters. It behaves similarly to _1
, but offers a way to use the first block parameter in one-liners without having to consider additional numeric parameters such as _2
. The innovation is intended to reduce the cognitive load when reading code that only uses the first parameter.
In Ruby 3.4, the default parser has been changed to Prism. According to the announcement post, this is more of an internal adjustment that should bring hardly any visible changes for most users – The aim is to optimize parser performance and stability.
Support for Happy Eyeballs 2
The socket library in Ruby 3.4.0 supports Happy Eyeballs version 2 (RFC 8305), which improves network connections. Happy Eyeballs is an algorithm that minimizes the delay in network connections by establishing and trying IPv6 and IPv4 connections simultaneously and using the fastest successful connection.
New for YJIT
Ruby 3.4 brings some new features for YJIT (Yet Another Just-in-Time Compiler), a just-in-time compiler for Ruby that is designed to improve the execution performance of Ruby programs by translating frequently executed Ruby methods into more efficient machine code at runtime. This results in faster execution of Ruby programs, especially for computationally intensive tasks.
The update overhauls performance on x86-64 and ARM64 platforms, has reduced memory consumption through compressed metadata and a unified memory limit. The development team introduces new command line options, such as --yjit-mem-size
for more intuitive memory management and --yjit-log
for creating a compilation log.
The update also includes new optimizations, such as the inlining of small methods. Inlining is an optimization technique in which the code of a method is inserted directly into the calling code block in order to reduce the overhead of function calls and increase the execution speed.
Changes to the language
Several changes have been made to the language in Ruby 3.4. Ruby now issues a deprecation warning when string literals are changed in files without a frozen_string_literal
comment. In addition, **nil
is treated as if no keywords are passed during keyword splatting, similar to **{}
. Keyword splatting in Ruby allows a hash or nil
to be passed to a method as keyword arguments using **
, where **nil
is treated as if no keyword arguments are passed.
The passing of blocks and the use of keyword arguments in index methods is no longer permitted in Ruby 3.4. Furthermore, the top-level name ::Ruby
is now reserved, and its definition triggers a warning if Warning[:deprecated]
is activated.
More information on Ruby 3.4 can be found in the announcement article on the official website for the programming language.
(mdo)