Ruby 3 brings parallel execution

Major Ruby update introduces an experimental feature called Ractor that promises thread-safe parallel execution

Ruby 3 brings parallel execution
graemenicholson / Getty Images

Ruby 3.0.0, an upgrade to the beloved open source dynamic language, arrived as a production release on Christmas Day. Highlights of the new version include parallel execution and type description capabilities.

Parallel execution comes in the form of an experimental feature dubbed “Ractor,” which is an Actor-model-like concurrency abstraction intended to provide parallel execution without thread safety concerns. Developers can make multiple ractors and run them in parallel. These parallel programs can be made thread safe because ractors cannot share normal objects. Communication between ractors is supported by message-passing. However, to limit sharing of objects, Ractor introduces restrictions to Ruby’s syntax.

Ruby 3.0.0 also introduces RBS, billed as a language to describe the types of Ruby programs. Ruby 3.0.0 ships with the rbs gem, which allows parsing and processing type definitions written in RBS. Type checkers including type profilers and other tools supporting RBS will understand Ruby programs better with RBS definitions.

RBS is intended to support commonly seen patterns in Ruby programs. Advanced types can be written including union types, method overloading, and generics. Duck typing with interface types also is supported. 

Aside from Ractor and RBS, Ruby 3.0.0 offers a host of other capabilities:

  • Fiber#scheduler, for intercepting blocking operations. Previously identified as Thread#scheduler, the capability allows for lightweight concurrency without changing existing code.
  • Memory view, another experimental feature, is a C-API set to exchange a raw memory area, such as a numeric array or a bitmap image, between extension libraries. These libraries also can share the metadata of the memory area that consists of the shape, the element form, etc.
  • Improved performance in the Ruby MJIT (Method-based Just In Time) compiler.
  • Separation of keyword arguments from other arguments.
  • Hash#except built in.
  • A rightward assignment statement.
  • An endless method definition.
  • The addition of find pattern.

Developers can download Ruby 3.0.0 from Ruby 3.0.0 was unveiled as a preview on September 25, 2020. This was followed by a subsequent preview on December 8 and a release candidate on December 20.

Copyright © 2021 IDG Communications, Inc.

InfoWorld Technology of the Year Awards 2023. Now open for entries!