Paul Krill
Editor at Large

Ruby backs WebAssembly for CRuby binaries

news
Jan 3, 20233 mins

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
Credit: Aleksey Nemiro

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.
Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author