What is New in Ruby 3.2
Ruby 3.2 delivers major performance boosts through the production-ready YJIT compiler, new language syntax improvements, enhanced debugging tools, and better security for regular expressions. It also introduces immutable value objects with Data class and makes several standard libraries more efficient while removing some deprecated features.
Performance Improvements
YJIT is now production-ready and offers significant speed gains:
- Supports x86-64 and arm64 platforms on Linux, macOS, and more, including Apple Silicon and Raspberry Pi.
- Up to 41% faster on benchmarks compared to the interpreter.
- Reduced memory usage with lazy allocation and Code GC that frees unused JIT code.
- New runtime stats like code_gc_count and live_page_count available in RubyVM::YJIT.runtime_stats.
- Optimizations using object shapes and finer constant invalidation.
- Default execution memory size increased to 64 MiB.
MJIT has been reimplemented in Ruby, now using a forked process for compilation.
Other enhancements include faster Regexp matching with memoization (most cases now linear time) and a new Regexp timeout feature to prevent ReDoS attacks.
Language Features
- Anonymous rest and keyword rest arguments can be forwarded directly.
def foo(*) bar(*) end
def baz(**) quux(**) end
New Core and Standard Library Features
A new immutable value class called Data is added:
Measure = Data.define(:amount, :unit)
distance = Measure.new(100, 'km')
weight = Measure.new(amount: 50, unit: 'kg')
weight.with(amount: 40) # Creates a new instance
Set is now a built-in class, no longer requiring require "set".
Struct supports keyword initialization by default without needing keyword_init: true.
New methods added:
- MatchData#byteoffset
- String#byteindex, String#byterindex, and String#bytesplice
- Module#refinements, Module#used_refinements, and Module#const_added
- Refinement#refined_class
RubyVM::AbstractSyntaxTree gains error-tolerant parsing and token preservation options.
Unicode updated to version 15.0.0.
Debugging and Error Handling
- SyntaxSuggest integrated to point out missing or extra end keywords.
- ErrorHighlight shows the exact argument causing TypeError or ArgumentError in backtraces.
- Regexp.timeout introduced for global or per-regexp timeouts to mitigate denial-of-service attacks.
Regexp.timeout = 1.0
/^a*b?a*()\1$/ =~ "a" * 50000 + "x" # Raises Regexp::TimeoutError if too slow
Compatibility Changes
Removed deprecated items:
- Constants: Fixnum, Bignum, Random::DEFAULT
- Methods: Dir.exists?, File.exists?, Kernel#=~, taint/trust related methods
Psych and fiddle no longer bundle libyaml and libffi sources; system libraries are required.
Hash#shift now returns nil when the hash is empty.
Some C API changes and removals for extensions.
Other Notable Changes
- Initial support for WASI-based WebAssembly, allowing Ruby to run in browsers and edge environments.
- Many default and bundled gems updated, including RubyGems 3.4.1, Bundler 2.4.1 (with new resolver), IRB 1.6.2, and others.
- IRB improvements with better integration for debugging commands.