What is new in Ruby 3.3

It’s official, Ruby 3.3 has arrived, bringing a wave of excitement to the Ruby community.

In this blog, we will go through the latest features, enhancements, and bugfixes introduced in the Ruby 3.3

Prism Parser

Ruby 3.3 introduces Prism, a new, portable, and maintainable parser offering improved reliability and performance. It is now the default gem and we can use it in place of Ripper. Prism is ready for production use and already being used by CRuby, JRuby, TruffleRuby, Rubocop, and many others.

YJIT

YJIT is a Just-In-Time compiler developed by Shopify and was released in Ruby 3.1, but with Ruby 3.3 it comes with major performance improvements, faster application startup, and less memory usage.

Performance improvements

  • Support for splat and optional parameters in methods has been improved.
  • Instead of making costly function calls for key methods like Integer#!=,String#!=, Module#===, Kernel#block_given? and more, YJIT embeds the code directly into the calling function. This will make core tasks like comparisons and type-checks become lightning-fast.
  • Inlines methods like #blank? and #present from Rails.
  • Faster compilation than Ruby 3.2

New Features

  • RubyVM::YJIT.enable has been introduced, which allows us to enable YJIT at runtime.
  • Rails 7.2 will enable YJIT by default by using RubyVM::YJIT.enable.

RJIT

RJIT is an experimental Just-In-Time compiler written in pure Ruby. It replaces the current implementation of MJIT. It doesn’t require any external compilers like Rust or C, making it more portable and potentially easier to maintain, but it’s currently limited to the x86-64 architecture on Unix platforms.

While RJIT holds promise for future performance improvements, it’s essential to remember that it’s still in its early stages and not recommended for production use. YJIT remains the default and preferred option for most Ruby 3.3 users

M:N Thread Scheduler

The M:N thread scheduler, introduced in Ruby 3.3, is a significant improvement to how our Ruby programs handle concurrent tasks. it is introduced to improve thread and ractor performance and here, M refers to number of ractors and N refers to the number of native threads.

IRB

IRB has got a lot of enhancements in the Ruby 3.3 release. Some of the major enhancements are

  • Integration of debug gem with IRB by introducing irb:rdbg session, which will allow to use all debug commands without exiting the IRB session.
  • Customizing the Dropdown UI with Reline::Face.
  • Introduced history command to display all stored input history.
  • Pager support for show_source, ls, show_cmds, and history commands.
  • We can now omit the return value with ;. It will make easier to inspect the long outputs.
  • show_source commands now support -s flag to get the method’s super definition and it can now display private methods too.

Performance warnings

Ruby 3.3 added a new warning category for performance related concerns. This category would be disabled by default and can be enabled in development.

Range#Overlap?

Ruby 3.3 introduces range#overlap?(range) method to compare two ranges and see if they overlap each other.

Range#reverse_each

Range#reverse_each can now process beginless ranges with an Integer endpoint and raises TypeError for endless ranges.

Range#size

Ruby 3.3 fixed a bug in the Range#size method related to rational endpoints, ensuring accurate counting.

Duplicate Keyword Argument

Ruby 3.3 fixes inconsistent warnings for duplicate keyword arguments. We will now get a warning when overwriting a previously provided keyword argument.

Optimize String.dup

Ruby 3.3 optimizes String.dup to match the speed of String#+, allowing developers to choose based on preference without sacrificing performance.

Deprecations

Following methods are deprecated in favor of using IO.popen

  • Kernel#open
  • URI.open
  • IO.binread
  • IO.foreach
  • IO.readlines
  • IO.read
  • IO.write

  • Calling a method called it without args has been deprecated and will show a warning. it will be a reference to the first block parameter in Ruby 3.4.

Need help on your Ruby on Rails or React project?

Join Our Newsletter