Skip to content

sisshiki1969/monoruby

Repository files navigation

monoruby

Rust codecov justforfunnoreally.dev badge

Ruby implementation with yet another JIT compiler written in Rust.

Presentation

  • Presentation movie and slides for RubyKaigi2024 is here.
  • Presentation movie and slides for RubyKaigi2025 is here.

Features

  • Written in Rust from scratch. No dependencies on any other Ruby implementations.
  • Fast. Currently, monoruby is comparable to ruby3.4.1+YJIT in the optcarrot benchmark.
  • Hand-written original parser.
  • Register-based bytecode.
  • Bytecode executor (virtual machine) written in x86-64 assembly (yes, we currently support only x86-64!).
  • A compact and fast just-in-time compiler. (internally using self-made dynamic assembler monoasm)

Prerequisites

Platform

Currently, only x86-64/linux is supported.

How to run

Please see wiki for details.

(1) Install nightly Rust.

First of all, install Rust nightly. Check here to install Rust

Caution!! only nightly Rust works for monoruby. See here to work with nightly Rust.

(2) Clone this repository.

> git clone https://github.com/sisshiki1969/monoruby.git
> cd monoruby

(3) Build and run monoruby with Ruby script file.

> cargo run --release -- test.rb

(4) or, Launch REPL.

> cargo run --bin irm

or

> bin/irm

Using monoruby in GitHub Actions

This repository doubles as a setup-monoruby action (see action.yml), modeled after ruby/setup-ruby. The ref after @ selects the monoruby version to install:

steps:
  - uses: sisshiki1969/monoruby@master # or a release tag
  - run: monoruby my_script.rb

The action first tries to download a prebuilt binary attached to a GitHub release (built by the release binaries workflow), which installs in seconds: release tags use their own release's assets, while @master / @latest use the rolling latest nightly prerelease, rebuilt on every master push (so it can lag a just-pushed HEAD by one build, ~15 min). Automatic builds cover x86-64 Linux only; assets for Linux arm64 and macOS arm64 are published on demand by dispatching the release binaries workflow with the wanted tag and targets. When no asset exists for the ref/platform — or prefer-prebuilt: 'false' is set — the action falls back to building monoruby from source on the first run for each monoruby revision × runner OS/arch and caches the resulting binary and runtime tree with actions/cache, so subsequent runs restore in seconds. Linux (x64/arm64) and macOS (Apple Silicon) hosted runners are supported either way.

Inputs and outputs:

Name Kind Description
prefer-prebuilt ('true') input Set to 'false' to skip release assets and build the exact ref
cache ('true') input Set to 'false' to disable the source-build cache
cache-version ('v1') input Mixed into the cache key; bump to discard existing caches
prebuilt output 'true' if a prebuilt release asset was used
cache-hit output 'true' if the built binary was restored from cache
monoruby-version output Output of monoruby --version
ruby-version output RUBY_VERSION reported by the installed monoruby

Benchmark

1. Optcarrot banechmark

Several Ruby implementations described below were measured by optcarrot benchmark. Please see wiki for details.

Versions of used Rubies

  • ruby 3.4.0dev (2024-04-27T08:56:20Z master 9ea77cb351) [x86_64-linux]
  • truffleruby 24.0.1, like ruby 3.2.2, Oracle GraalVM JVM [x86_64-linux]
  • truffleruby 24.0.1, like ruby 3.2.2, Oracle GraalVM Native [x86_64-linux]
  • monoruby: 3e348afd4141c40978342e67ad26d42dc0b8d2a7

Optcarrot benchmark

optcarrot_benchmark

Optcarrot fps history (0-3000 frames)

optcarrot_fps_history

2. Other benchmarks

Several Ruby implementations described below were measured by yjit-bench. Please see wiki for details.

Versions of used Rubies

  • monoruby: monoruby 0.3.0
  • yjit: ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +PRISM [x86_64-linux]
  • truffleruby-24.1.1: truffleruby 24.1.1, like ruby 3.2.4, Oracle GraalVM Native [x86_64-linux]

Results

The graph shows the speed ratio against truffleruby. (higher is better)

micro_bench

About

Ruby implementation with yet another JIT compiler.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

140 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages