Trying out Ruby 2.6's JIT feature
Ruby’s JIT (Just in Time) compilation feature
As an experiment I tried running my Project Euler ruby solutions with and without JIT on Ruby 2.6.2.
The idea there is that any block of code that needs to run more than a handful of times gets compiled into a
more performant intermediate representation that essentially runs at native speed on the Ruby VM.
The first 11 problems are pretty trivial for vanilla Ruby, but my solution to number 12 takes 42 seconds.
With the --jit
flag however it only took 21 seconds. That’s twice the speed! Nice.
🍔 euler 13:24$ ruby ruby/test.rb
Problem | Status | Time |
---|---|---|
001 | Correct | 0.00008 |
002 | Correct | 0.00001 |
003 | Correct | 0.00004 |
004 | Correct | 0.08071 |
005 | Correct | 0.00005 |
006 | Correct | 0.00001 |
007 | Correct | 0.02941 |
008 | Correct | 0.00700 |
009 | Correct | 0.61022 |
010 | Correct | 1.58422 |
011 | Correct | 0.00039 |
012 | Correct | 42.22998 |
🍔 euler 13:25$ ruby --jit ruby/test.rb
Problem | Status | Time |
---|---|---|
001 | Correct | 0.00008 |
002 | Correct | 0.00001 |
003 | Correct | 0.00004 |
004 | Correct | 0.08574 |
005 | Correct | 0.00019 |
006 | Correct | 0.00002 |
007 | Correct | 0.03007 |
008 | Correct | 0.00092 |
009 | Correct | 0.62826 |
010 | Correct | 1.58222 |
011 | Correct | 0.00065 |
012 | Correct | 21.27108 |
Sweet, let’s try it with Rails
.rvm/gems/ruby-2.6.2/gems/activerecord-5.2.3/lib/active_record/relation/predicate_builder.rb:32:
[BUG] Segmentation fault at 0x0000000119788918 Time: 00:00:04
ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-darwin18]
… maybe not just yet. :)