Ruby 3.1 lands with new debugger in tow

Ruby 3.1

As has become the custom, the team behind Ruby has used the end-of-year holiday break to push out a feature update for the programming language. Version 3.1 is now available and mostly bestows performance and debugging improvements upon developers.

Amongst the highlights of version 3.1 is a new debugger that replaces lib/debug.rb. According to Ruby committer Yui Naruse, lib/debug.rb wasn’t well maintained and showed some performance and feature issues. 

The new debug.gem is meant to put an end to those by not slowing down applications when looking for errors and sporting useful capabilities for remote and multi-thread debugging. It also includes record and replay functionality, a tracing feature, and supports Visual Studio Code as well as the Chrome browser as debugging front ends.

To improve the debugging experience even further, Ruby 3.1 ships with an error_highlight gem, which is enabled by default and adds more precise error locations to backtraces. IRB users who want to prevent making mistakes in the first place now have an autocompletion function with documentation dialog at their disposal. 

Another interesting addition is the new in-process JIT compiler YJIT. The feature is still experimental and limited to Unix-like x86-64 platforms, but promises a short warmup as well as speedups “from 15 to 19 per cent” over the CRuby interpreter. 

YJIT was developed at Spotify to improve the performance of the team’s Ruby on Rails applications, through an approach called Lazy Basic Block Versioning. In it, only the beginning of a method is compiled at first, while the rest follows incrementally once the type of arguments and variables have been dynamically determined. Developers interested in trying the new compiler can activate it using the --yjit command-line option.

Users of Ruby’s regular JIT compiler MJIT won’t have to miss out on performance improvements when working with Rails, as the tool now comes with a larger maximum default cache and won’t cancel code should a TracePoint for class events be enabled.

In terms of pure language changes, Ruby 3.1 lets programmers omit values in hash literals and keyword arguments, so that they can now write {x:, y:} instead of {x: x, y: y}. This is meant to help create more concise code, just as the newly added option to skip the parentheses in one-line pattern matching. The latter graduated from its experimental status with the current release, while the ^-operator in pattern matching learned to accept an expression.

Operational folks will surely know Ruby through its use in automation tools Puppet and Chef, though it is mainly used for building web applications such as Airbnb and Spotify. The last big release was shared in December 2020 and looked to make the language three times faster than the 2.x series of the language. The hoped-for surge in interest seems to have failed to materialize, however, as language rankings saw the language stagnating (PYPL) or even dropping (TIOBE; currently on 18 compared to 15 in January 2021) in popularity in 2021.