Posted by naruse on 9 Nov 2021
We are pleased to announce the release of Ruby 3.1.0-preview1.
YJIT: New experimental in-process JIT compiler
Ruby 3.1 merges YJIT, a new in-process JIT compiler developed by Shopify.
Since Ruby 2.6 introduced MJIT in 2018, its performance greatly improved, and finally we achieved Ruby3x3 last year. But even though Optcarrot has shown impressive speedups, the JIT hasn’t benefited real world business applications.
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 macOS & Linux on x86-64 platforms for now.
- https://bugs.ruby-lang.org/issues/18229
- https://shopify.engineering/yjit-just-in-time-compiler-cruby
- https://www.youtube.com/watch?v=PBVLf3yfMs8
debug gem: A new debugger
A new debugger debug.gem is bundled. debug.gem is fast debugger implementation and it provides many features like remote debugging, colorful REPL, IDE (VSCode) integration and more. It replaces lib/debug.rb
standard library.
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
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 improvement
To be described in next preview.
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 offoo(x: x, y: y)
.
- Pin operator in pattern matching now takes an expression. [Feature #17411]
Prime.each_cons(2).lazy.find_all{_1 in [n, ^(n + 2)]}.take(3).to_a
#=> [[3, 5], [5, 7], [11, 13]]
RBS
RBS is a language to describe the structure of Ruby programs. See the repository for detail.
Updates since Ruby 3.0.0:
rbs collection
has been introduced to manage gems’ RBSs. doc- Many signatures for built-in and standard libraries have been added/updated.
- It includes many bug fixes and performance improvements too.
See the CHANGELOG.md for more information.
TypeProf
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.
Updates since Ruby 3.0.0:
- Experimental IDE support has been implemented.
- 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.
- For workloads like Rails, the default
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 orderbaz
,qux
,foo
, and thenbar
in Ruby 3.0. In Ruby 3.1, it is evaluated in orderfoo
,bar
,baz
, and thenqux
.
- Variable Width Allocation: Strings (experimental) [Bug #18239]
Standard libraries updates
- Some standard libraries are updated.
- RubyGems
- Bundler
- RDoc 6.4.0
- ReLine
- JSON 2.6.0
- Psych 4.0.2
- FileUtils 1.6.0
- Fiddle
- StringIO 3.0.1
- IO::Console 0.5.9
- IO::Wait 0.2.0
- CSV
- Etc 1.3.0
- Date 3.2.0
- Zlib 2.1.1
- StringScanner
- IpAddr
- Logger 1.4.4
- OStruct 0.5.0
- Irb
- Racc 1.6.0
- Delegate 0.2.0
- Benchmark 0.2.0
- CGI 0.3.0
- Readline(C-ext) 0.1.3
- Timeout 0.2.0
- YAML 0.2.0
- URI 0.11.0
- OpenSSL
- DidYouMean
- Weakref 0.1.1
- Tempfile 0.1.2
- TmpDir 0.1.2
- English 0.7.1
- Net::Protocol 0.1.2
- Net::Http 0.2.0
- BigDecimal
- OptionParser 0.2.0
- Set
- Find 0.1.1
- Rinda 0.1.1
- Erb
- NKF 0.1.1
- Base64 0.1.1
- OpenUri 0.2.0
- SecureRandom 0.1.1
- Resolv 0.2.1
- Resolv::Replace 0.1.0
- Time 0.2.0
- PP 0.2.1
- Prettyprint 0.1.1
- Drb 2.1.0
- Pathname 0.2.0
- Digest 3.1.0.pre2
- Un 0.2.0
- The following bundled gems are updated.
- minitest 5.14.4
- power_assert 2.0.1
- rake 13.0.6
- test-unit 3.5.0
- rbs 1.6.2
- typeprof 0.20.0
- The following default gems are now bundled gems.
- net-ftp
- net-imap
- net-pop
- net-smtp
- matrix
- prime
See NEWS or commit logs for more details.
With those changes, 2963 files changed, 529321 insertions(+), 92305 deletions(-) since Ruby 3.0.0!
Download
-
https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.0-preview1.tar.gz
SIZE: 20821221 SHA1: 40dfd3db076a49fab9a0eee51e89d9b3d16a4e23 SHA256: 540f49f4c3aceb1a5d7fb0b8522a04dd96bc4a22f9660a6b59629886c8e010d4 SHA512: 63f528f20905827d03649ed9804e4a4e5c15078f9c6c8efcfb306baa7baafa17a406eb09a2c08b42e151e14af33b1aadbd9fb1cc84f9353d070b54bbf1ff950d
-
https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.0-preview1.tar.xz
SIZE: 15742844 SHA1: 22aa861b17031cd1b163b7443f5f2f5897c5895e SHA256: 86a836ad42f6a7a469fce71ffec48fd3184af55bf79e488b568a4f64adee551d SHA512: bdbd7c624197ca478658280d84123a8c12ae72425bc566dcc75989c5b5ef114dd57e64efc09e2413ed615d9b47621a70ace0f3612e8ca7ba853822ad9e88c0b0
-
https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.0-preview1.zip
SIZE: 25019629 SHA1: ef5fa22890e55935db4b96b3089a8aea1335bd85 SHA256: 4e8d118b2365164873148ac545a8fa36c098b846a9b19ebb9037f8ee9adb4414 SHA512: 917803aac0848e00871614a09740b5c9cca26f200d68580dde61666633f1b7fee506e25ea4ed0c38eb20149417bf9f1ed449a4d2aec5b726de670e7177e5c07a
What is Ruby
Ruby was first developed by Matz (Yukihiro Matsumoto) in 1993, and is now developed as Open Source. It runs on multiple platforms and is used all over the world especially for web development.