See all articles

Ruby 3.1 – what is new?

Paweł Dąbrowski-Chief Technology Officer

Ruby 3.1 is strongly focused on improving the performance of both the development process and the final product. Discover what’s changed in the latest Ruby release!

The latest version of Ruby – Ruby 3.1 was released on December 25th, 2021. It comes with significant improvements in terms of performance and features. Over 3k files were changed for the new version.

In this article, we’ll go through the changes brought by Ruby 3.1 and what they mean for both the development process and the way applications work.

The new version is compatible with Ruby 3.0, which had been launched one year before. Since then, Ruby on Rails has been experiencing a renaissance. At the end of 2021, a few days before the release of Ruby 3.1, a new Rails version – Rails 7.0 was shipped too. The delivered features contributed to increased app security, more cost-effective maintenance and development, and improved app performance and user experience. If you’re interested in the latest Rails version as well, check out our blog post about the release notes of Rails 7.0.

Improved performance

Ruby 3.1 merges YJIT, a new in-process JIT compiler. It improves the performance of applications, especially those created with the Ruby on Rails framework. The shift in performance is significant – Shopify’s developers who created YJIT managed to improve it from 22% up to 39%.

For most users, this improved performance is the most notable change introduced with Ruby 3.1, as the previous compiler, called MJIT, was shipped in Ruby 2.6 back in 2018 but didn’t improve the performance of real-world business applications.

Note that YJIT is an experimental feature at this point. Therefore it’s disabled by default.

A look at Ruby 3.1 new features

Apart from the new compiler, Ruby 3.1 comes with several other improvements that focus on enhancing performance and providing new useful features.

First of all, the new, completely rewritten debugger library was introduced as a powerful alternative to the standard library. The rewritten debugger:

  • Supports remote debugging: which results in easier debugging when the Ruby application is running with Docker or as a daemon.
  • Improves the debugging performance: the library doesn’t slow down the application if you are not using any breakpoints in the code.
  • Comes with a better user experience: thanks to the new colorful interface.
  • Adds support for a rich debugging frontend: by providing integration with Visual Studio Code and Google Chrome.

Also, backtracing output when an error is raised is now easier thanks to a new a new built-in library:

  • It shows which part of the code was responsible for the error, not only the line where the error was raised.
  • The output provided by the library can be modified but the API is still in experimental mode and will possibly be changed in the future.
  • The library is enabled by default.

Support for documentation and autocomplete are now integral features of the interactive Ruby console (IRB). It means that:

  • Each time you write the code, the autocomplete dialog suggests the name of the function you can execute in the current context.
  • If the documentation is installed, a part of the documentation is rendered next to the autocompletion dialog. By pressing Alt+d you can read the full documentation.

Ruby 3.1 – what was improved?

Apart from the new features mentioned above, the new release came with a number of important improvements which include:

  • There is no longer a need to use parentheses in one-line pattern matching.
  • The pin operator (^) is now able to take expression as an argument.
  • Values in both Hash literals and keywords may be omitted.
  • The RBS language which is used to describe the structure of Ruby programs, received many bug fixes, performance improvements, and other changes, such as introducing support for generic type aliases or the new RBS collection feature that allows managing other gems’ RBSs.

Update your app to Ruby 3.1

Ruby 3.1 is strongly focused on improving app and development performance, proving itself useful for existing, as well as new product teams.

If you’re looking to upgrade to the latest features of Ruby and/or Rails, our experts can help you with ensuring your app's top performance, security, and scalability. Get in touch with us, and let's see how an update can fuel your digital product.

Similar articles