130 points · by bensummers · 10y ago · 36 comments
I haven't looked at the benchmarks, but are they synthetic or are they actually relevant to typical rails usage?
See our Acid Test benchmark for an exteme example http://chrisseaton.com/rubytruffle/pushing-pixels/
Evan Phoenix recently said at RubyKaigi that a weaker version of this benchmark is the standard that Ruby 3 should be aiming at.
Might the difference simply be test coverage?
-- The other Ruby implementations have been testing performance on those same synthetic benchmarks, and have already taken the opportunity to improve performance for those cases.
-- The other Ruby implementations have not been testing performance in other cases, and still have considerable opportunity to improve performance for those cases.
Real Ruby code uses a lot of abstraction, allocates objects constantly, and uses metaprogramming. Optimising these aspects of Ruby is much more complex and doing it well requires some optimisations such as partial escape analysis and powerful allocation removal that we have and JRuby and Rubinius do not.
My favourite example is this code from PSD.rb that implements a clamp routine. It does it by creating an array, sorting and finding the middle value. You wouldn't normally find code like this in a synthetic benchmark, but you would in real code.
def clamp(value, min, max)
[value, min, max].sort[1]
end
In JRuby and Rubinius that code really will allocate an array, sort it using some library routine, and then index it. In JRuby+Truffle we compile that method to effectively: def clamp(value, min, max)
(value > max) ? max : ((value < min) ? min : value);
end
There's a massive massive difference between those two. One allocates objects on the heap, passes them into the runtime, runs a general purpose sort routine etc etc etc, thousands of machine instructions, and the other is a just couple of assembly instructions.When you run this code as a benchmark, we're over 300x faster than Rubinius' LLVM-based JIT.
Of course we still support if someone has redefined Array#sort or something like that, and you could still find that Array instance using ObjectSpace if you wanted to, using deoptimisation.
Would love to try it out if you did.
https://github.com/jruby/jruby/blob/master/lib/ruby/truffle/...
Re: Rails ... there's still a fair bit of work involved there. We've been working on passing all the ActiveSupport tests (we're currently at 99%), as that's a core dependency. We haven't looked much into the other gems. Things like ActiveRecord simply won't work since we currently don't run C or Java extensions. I think it's a bit more likely we'll start with a custom driver of some sort with an ActiveModel front-end. I strongly suspect the asset pipeline and Spring will present problems, as well. The rest of Rails should pull together somewhat quickly and that's a big goal for us in 2016.
The JS equivalent of JRuby+Truffle is called Graal.js, and is available today from here http://www.oracle.com/technetwork/oracle-labs/program-langua....
You'd need to understand Java and Ruby, but we can help you with the rest.
Join us #jruby on Freenode IRC, or https://gitter.im/jruby/jruby.
http://chrisseaton.com/rubytruffle/cext/
People are now working on an LLVM bitcode interpreter instead, as this should support many languages not just C. There will be info about this at FOSDEM.
You could spend a whole bunch of time on this and actually not make an impact on people who actually use jruby in production
EDIT: now that I think of it, there's one extension that would be very useful - libgit2 + Rugged.
Of course, rather than trying to fix the general problem, we could support the most common JRuby gems out there or the core subset of the API they use. These are just the sorts of things we need to look at a bit more.
@chrisseaton is startup time similar to today's JRuby, i.e. slow? I feel like that's always been a bit of a sticking point for JRuby.
In addition to the steps we're taking, there's a sister project in Oracle Labs called the Substrate VM that would allow us to build a static binary with startup time on par with MRI. I can't speak to release plans or timelines on anything. I only mention it to show that startup time is a concern for us and we're thinking about how to fix it in a wide variety of ways.