TruffleRuby Native: Fast Even for Short Scripts

Last updated 1 year ago by Benoit Daloze



Nowadays, it seems every major Ruby implementation has a Just-In-Time (JIT) compiler. Recently, YARV-MJIT has been merged to MRI (CRuby) trunk. JRuby relies on the Java Virtual Machine JIT compilers, and TruffleRuby uses Graal.

One big challenge for JIT compilers is to be beneficial on short-running scripts. In general, JIT compilers are better for long-running applications like web servers.

John Hawthorn Recently wrote a blog post about using YARV-MJIT for a small Ruby script. In this post, I want to expand on that and analyze the performance of 43 short-running programs (from 0.04s to 20s). Quick startup and fast warmup are therefore important to achieve good results.

JRuby and TruffleRuby on JVM do not perform well on short-running programs as their startup alone gives them a big disadvantage. On the other hand, TruffleRuby on SubstrateVM has much better startup and warmup.

TruffleRuby Native

TruffleRuby can run on 2 different virtual machines:

  • The HotSpot Java Virtual Machine, which has multiple just-in-time compilers and achieves the best peak performance. But the startup is not great (~2s), mostly due to classloading.
  • The SubstrateVM, which provides very fast startup and fast warmup.
  • In both cases, the Graal dynamic/just-in-time compiler is used to compile Ruby code down to machine code and obtain great peak performance.
Read full Article