But how does it fare with a more complex application?
Let’s try with a simple Sinatra app:
require 'sinatra'
get '/' do
"apples, oranges & bananas"
end
It may not look like much, but this little bit of code runs over 500 different methods. Enough to give the JIT some work to do!
To be specific, this is Sinatra 2.0.4 with Thin 1.7.2.
You can run the benchmark with this command (apache bench):
ab -c 20 -t 10 http://localhost:4567/
These are the results:
You can tell from these that Ruby 2.6 is faster than 2.5, but enabling the JIT makes Sinatra 11% slower!
Why?
I don’t know, it may be because overhead introduced by JIT, or because the code is not well optimized.
My testing with a C profiler (callgrind) reveals that the use of JIT optimized code (the compiled C files that we discovered earlier) is very low for Sinatra (less than 2%), but it’s very high (24.22%) for the while statement that gets a 8x speed boost.
Results for the while benchmark with JIT:
Results for Sinatra benchmark with JIT:
This may be part of the reason, I’m not a compiler expert so I can’t make any conclusions from this.
Summary
MJIT is a “Just-in-Time Compiler” available in Ruby 2.6, it can be enabled with the --jit flag. MJIT is promising & can speed up some small programs, but there is still a lot of work to do!
If you liked this article don’t forget to share it with your Ruby friends 🙂
Thanks for reading.
Related
3 comments
Tim says
4 years ago
For the last few minor releases I’ve been compiling ruby with jemalloc for improved memory allocation. Would this interfere with jit in ruby 2.6?
As far as I understand I don’t think it will interfere because the JIT doesn’t change how memory allocation works. The best way to find out is to download a preview version of Ruby 2.6 & try it out 🙂
Strange, I’m not getting any improvement using JIT in any of the test cases, only slow downs. I’m using 2.6.0 as well as trying with current ruby-edge off github. I did have to create my own tmp directory in my home directory because it was failing with permission problems to use the regular stock /tmp (this is RHEL 7.5) for some strange reason. Humm, I don’t doubt that JIT is awesome and can be very effective in some cases, but for some reason, it just isn’t working here. (fyi 8 cores x Intel(R) Xeon(R) Silver 4110 CPU @ 2.10GHz)