Recently Shopify contributed many Ruby improvements to speed up their Rails application. YJIT is an important contribution, and aims to improve the performance of Rails applications.
Though MJIT is a method-based JIT compiler and uses an external C compiler, YJIT uses Basic Block Versioning and includes JIT compiler inside it. With Lazy Basic Block Versioning (LBBV) it first compiles the beginning of a method, and incrementally compiles the rest when the type of arguments and variables are dynamically determined. See YJIT: a basic block versioning JIT compiler for CRuby for a detailed introduction.
With this technology, YJIT achieves both fast warmup time and performance improvements on most real-world software, up to 22% on railsbench, 39% on liquid-render.
YJIT is still an experimental feature, and as such, it is disabled by default. If you want to use this, specify the --yjit command-line option to enable YJIT. It is also limited to Unix-like x86-64 platforms for now.
A completely rewritten debugger debug.gem is bundled. debug.gem has the following features:
Improve the debugging performance (it does not slow down the application even with the debugger)
Support remote debugging
Support rich debugging frontend (VSCode and Chrome browser are supported now)
Support multi-process/multi-thread debugging
Colorful REPL
And other useful features like recod & replay feature, tracing feature and so on.
Ruby had bundled lib/debug.rb, but it was not well maintained and it had issues about performance and features. debug.gem replaced lib/debug.rb completely.
error_highlight: Fine-grained error location in backtrace
A built-in gem, error_highlight, has been introduced. It includes fine-grained error location in backtrace:
$ ruby test.rb
test.rb:1:in `<main>': undefined method `time' for 1:Integer (NoMethodError)
1.time {}
^^^^^
Did you mean? times
Currently, only NameError is supported.
This gem is enabled by default. You can disable it by using a command-line option --disable-error_highlight. See the repository in detail.
IRB Autocomplete and Document Display
The IRB now has an autocomplete feature, where you can just type in the code, and the completion candidates dialog will appear. You can use Tab and Shift+Tab to move up and down.
If documents are installed when you select a completion candidate, the documentation dialog will appear next to the completion candidates dialog, showing part of the content. You can read the full document by pressing Alt+d.
Other Notable New Features
Language
Values in Hash literals and keyword arguments can be omitted. [Feature #14579]
{x:, y:} is a syntax sugar of {x: x, y: y}.
foo(x:, y:) is a syntax sugar of foo(x: x, y: y).
Pin operator in pattern matching now takes an expression. [Feature #17411]
TypeProf is a static type analyzer for Ruby. It generates a prototype of RBS from non-type-annotated Ruby code. See the document for detail.
The main updates since Ruby 3.0.0 is an experimental IDE support called “TypeProf for IDE”.
The vscode extension shows a guessed (or explicitly written in a RBS file) method signature above each method definition, draws a red underline under the code that may cause a name error or type error, and completes method names (i.e., shows method candidates). See the document in detail.
Also, the release includes many bug fixes and performance improvements.
Performance improvements
MJIT
For workloads like Rails, the default --jit-max-cache is changed from 100 to 10000.
The JIT compiler no longer skips compilation of methods longer than 1000 instructions.
To support Zeitwerk of Rails, JIT-ed code is no longer cancelled
when a TracePoint for class events is enabled.
Other notable changes since 3.0
One-line pattern matching, e.g., ary => [x, y, z], is no longer experimental.
Multiple assignment evaluation order has been changed slightly. [Bug #4443]
foo[0], bar[0] = baz, qux was evaluated in order baz, qux, foo, and then bar in Ruby 3.0. In Ruby 3.1, it is evaluated in order foo, bar, baz, and then qux.
Here is everything you need to know about this upgrade. Please take a good look at what changed and the test results before merging this pull request.
What changed?
Release Notes
3.1.0
All Depfu comment commands