Ruby backs WebAssembly for CRuby binaries

Ruby 3.2.0 ships with initial WASI support, allowing CRuby binaries to be run in web browsers, serverless edge environments, and other WebAssembly/WASI embedders.

two rubies ruby
Aleksey Nemiro (CC0)

Ruby 3.2.0, an upgrade to the popular open source dynamic language introduced on Christmas Day, offers initial WASI (WebAssembly System Interface) support. WebAssembly and WASI support allows developers to create CRuby binaries that will run in web browsers, serverless edge environments, and other WebAssembly/WASI embedders.

Available at ruby-lang.org, Ruby 3.2.0 offers an initial port of WASI that passes basic and bootstrap test suites not using the Thread API. The WebAssembly binary instruction format was introduced to run programs safely and quickly in browsers, while also allowing language choice in web development.

Ruby’s developers said WASI and WebAssembly currently are missing features to implement Fiber, exception, and garbage collection. CRuby fills the gap by using Asyncify, providing binary transformation to control execution. Ruby’s developers also have built a virtual file system on top of WASI so that Ruby apps can be packed into a single .wasm file, making distribution of Ruby apps easier.

Ruby 3.2.0 also features a production-ready YJIT (Yet Another Ruby JIT), a lightweight, minimalistic JIT built inside CRuby. YJIT has been tested on production workloads for more than a year and is no longer experimental. Designed to improve application performance, and billed as 41% faster than the Ruby interpreter, YJIT lazily compiles code using a Basic Block Versioning (BBV) architecture. The target use case is servers running Ruby on Rails.

YJIT was featured in an experimental mode in Ruby 3.1, released one year earlier than Ruby 3.2. YJIT supports both x86-64 and arm64/aarch64 CPUs on Linux, macOS, BSD, and other Unix platforms. The new release also brings support for Apple M1/M2, AWS Graviton, and Raspberry Pi 4.

Also in Ruby 3.2.0:

  • The MJIT compiler has been re-implemented as ruby_vm/mjit/compiler, to improve performance.
  • An improved Regexp (regular expression) matching algorithm helps mitigate ReDoS (regular expression denial of service). As a fallback measure, a timeout feature for Regexp matches also has been introduced.
  • Set now is available as a built-in class without the need for require "set".
  • A syntax_suggest feature, formerly known as dead_end, has been integrated into Ruby to help find the position of errors such as missing or superfluous ends.
  • The ErrorHighlight capability now points at the relevant argument or arguments for TypeError and ArgumentError.
  • Anonymous rest and keyword rest arguments now can be passed as arguments, instead of just being used in method parameters.
  • String#byteindex and String#byterindex have been added, for byte operations for String.

Copyright © 2023 IDG Communications, Inc.