Loading…
Introducing Ruvy
2023-10-18
- Source
- Shopify
- Published
- Added to Yomu
Summary
Ruvy is an open-source toolchain that takes Ruby code as input and produces a WebAssembly module whose exported _start function executes that code. Built on ruby.wasm, it pre-initializes the Ruby virtual machine and includes Ruby files during the build, while avoiding the need to supply a Ruby script path as a WASI argument at runtime. In Wasmtime benchmarks, Ruvy’s instantiation and _start execution took about 44.4–45.2 ms, compared with 55.8–56.9 ms for ruby.wasm plus wasi-vfs, and its Wasm-to-native compilation took about 440–457 ms versus 1.62–1.68 seconds. These results correspond to roughly 20% faster runtime performance and about 70% less compilation time in the reported tests. Ruvy currently requires users to install build dependencies and compile it because precompiled binaries are not shipped.
Context
Ruby programs compiled with ruby.wasm and wasi-vfs start the Ruby virtual machine during WebAssembly execution and require a Ruby script path to be supplied as a WASI argument. The latter requirement can make execution difficult in computing environments that cannot provide additional WASI arguments, including various edge computing services.
Approach / What changed
Ruvy builds on ruby.wasm by pre-initializing the Ruby virtual machine during WebAssembly module creation, packaging Ruby files included by the script, and producing a module that does not require a file path as a WASI argument at runtime. Its CLI can also preload every file in a specified directory so those definitions are available to the input Ruby file.
Takeaways
- Ruvy’s reported Wasmtime execution benchmarks were about 44.4–45.2 ms, compared with 55.8–56.9 ms for ruby.wasm plus wasi-vfs.
- Ruvy’s reported Cranelift compilation benchmarks were about 440–457 ms, while ruby.wasm plus wasi-vfs took about 1.62–1.68 seconds.
- Ruvy does not currently ship precompiled binaries; users must install build dependencies and compile the toolchain before using it.