High-performance Ruby

Run your Ruby code faster on GraalVM's Ruby implementation, TruffleRuby

Benefits

small footprint advantage icon

Running Ruby code faster

TruffleRuby is the fastest Ruby implementation for many CPU-intensive benchmarks
improved security advantage icon

Executing Ruby code in parallel

TruffleRuby runs Ruby Threads in parallel, it has no global interpreter lock for Ruby code
fast startup advantage icon

Supporting C extensions

Many C extensions work out of the box, including database drivers
ideal for containers advantage icon

Low-overhead interoperability with Java, JavaScript, Python and R

Provided by the GraalVM Polyglot API
microservices advantage icon

Maintaining high compatibility with the standard Ruby

TruffleRuby aims to be fully compatible with the standard Ruby runtime (MRI/CRuby) along with extra functionality provided by JRuby
clouds advantage icon

Providing tooling such as debuggers and monitoring

The tooling support includes a profiler, debugger, VisualVM, and more, and works across languages

Faster Ruby with TruffleRuby and GraalVM

Optcarrot Benchmark

TruffleRuby JVM CE is 4.2x faster than CRuby 3.0 and TruffleRuby JVM EE is 8.2x faster than CRuby 3.0
optcarrot benchmark

Rubykon Benchmark

TruffleRuby JVM CE is 7.3x faster than CRuby 3.0 and TruffleRuby JVM EE is 10.6x faster than CRuby 3.0
rubykon benchmark
box

TruffleRuby is able to run a key production Ruby application almost entirely unmodified from the standard Ruby configuration at Shopify, making it the only realistic option for migrating to a Ruby implementation with genuine potential for seriously increasing the performance and tooling of Ruby.

box
Chris Seaton
Senior Staff Engineer at Shopify

Try Examples

require 'sinatra'
  require 'some-c-extension'
  get '/' do
    CExtensions.work!
  end

Run your existing code unchanged, including native extensions

TruffleRuby runs Rails and is the only implementation besides CRuby to pass all RubyGems tests.
array = Java.type('int[]').new(4)
  array[2] = 42
  p array[2]

Accessing Java from Ruby

Reuse any JVM library.
$ ruby --cpusampler app.rb
Name                       | Total Time |Opt%||  Self Time |Opt%
----------------------------------------------------------------
Optcarrot::PPU#main_loop   |3372ms 64.5%| 98%||1991ms 38.1%| 99%
Optcarrot::PPU#render_pixel| 309ms  5.9%| 80%|| 309ms  5.9%| 80%

$ ruby --inspect app.rb
Debugger listening on ws://127.0.0.1:9229/...
For help, see: https://www.graalvm.org/docs/tools/chrome-debugger
E.g. in Chrome open: devtools://devtools/bundled/js_app.html?ws=127.0.0.1:9229/...

Includes a Built-in Sampling Profiler and Debugger

As well as VisualVM, Flamegraphs and more.

  $ ruby -ropen-uri -e 'URI.open("https://expired.badssl.com/", &:read)'
  cext.rb:1096:in `rb_exc_raise': certificate has expired (OpenSSL::SSL::SSLError)
  from openssl/ossl.c:300:in `ossl_raise'
  from openssl/ossl_ssl.c:1697:in `ossl_start_ssl'
  from openssl/ossl_ssl.c:1755:in `ossl_ssl_connect_nonblock'
  from net/protocol.rb:44:in `ssl_socket_connect'
  from net/http.rb:1021:in `connect'
  from ...
  from -e:1:in `main'
  

Backtraces in C Extensions

GraalVM can execute and compile Ruby and C code together.

Making a Difference for Real-World Applications

Running Rack and Rails Faster on GraalVM with TruffleRuby

Optimizing Rack and Rails applications with a just-in-time (JIT) compiler is a challenge. For example, MJIT does not speed up Rails currently. The GraalVM team took this challenge on and now TruffleRuby achieves higher performance than any other Ruby implementation on the Rails Simpler Benchmarks. See how TruffleRuby got there and what optimizations are useful for Rack and Rails applications.

Try GraalVM for Your Ruby Applications

Connect with us