Ruby 3 previews parallel execution
- 30 September, 2020 12:50
Ruby 3.0.0, a planned upgrade to the long-established open source dynamic language, is now available as a preview. 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.
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, the Ruby 3.0.0 release is slated to offer a host of other capabilities:
- A scheduler, also in the experimental stage, for intercepting blocking operations. 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.
- A rightward assignment statement.
- An endless method definition.
- The addition of find pattern.
Unveiled September 25, the Ruby 3.0.0 preview is downloadable from ruby-lang.org. For the second preview, Ruby’s builders plan to include a type profiler, which serves as a static analysis feature. The current stable releases of Ruby are versions 2.7.1 and 2.6.6.