Thanks for bringing this to the list! Comments below.
On Wed, Apr 18, 2012 at 12:52 PM, David B. [email protected]
wrote:
what you did… oh… you’re not relating to that one? Ok, “awkward” is
what I’m going for here. Awkward.
I ran JRuby with the following options:
–1.9 --server -Xcompile.mode=FORCE --fast
These options are fine, though with 1.6+ you don’t really need --fast
(almost everything interesting it does became default in 1.6).
JVM version does make a difference; Oracle/OpenJDK 7 (1.7) is faster,
and in combination with JRuby 1.7 it can be even faster for running
Ruby code.
I thought with those options pitting JRuby against MRI would be like
shooting fish in a barrel (or your girlfriend’s fish tank) given how I
imagine JSON parsing/generation would work and all the magical
optimisations I imagine JRuby would be able to do in those cases.
Comments on the individual JSON impls you tested…
YAJL:
Anything C extension-based is going to be slow on JRuby (and every
impl except MRI, for various reasons). We discourage using C exts and
our support for them in 1.6 was mostly an olive branch.
Oj:
Same statement as above, I would imagine. I’m amazed either of them
worked as well as they did
json-pure:
This is pure Ruby, so it’s always going to suffer compared to native
code. However, JRuby 1.7 on Java 7 should do considerably better than
other Rubies, earlier JRubies, or earlier Javas. There are some cases
where JRuby + Java 7 results in worse performance than JRuby + Java
6; if that’s the case here, I really want to know.
json-jruby:
At this point I believe you should just use the “json” gem, which
includes the json-jruby stuff, or the “json” 1.9.3 library in JRuby
master which is the same thing.
I have looked into the performance of the json gem a few times, and
more recent builds (last few months) should have some perf
improvements I made. Ultimately the remaining performance issue comes
down to problems with the generated json code we can’t really do
anything about (since it’s generated by Ragel) and really has nothing
to do with JRuby.
I’d love to see a port of Oj (or YAJL) to Java that we could connect
with directly, but I don’t know of any plans for someone to do that.
The bottom line is that you’re really testing a library and the
integration with it rather than individual impls here. MRI + C exts
can be very fast. JRuby + C exts is slow. MRI + Ruby code can be slow.
JRuby + Ruby code can be pretty fast. JRuby + Java libraries can be
fast, if the libraries themselves are fast.
I hope that clears things up. I’d love to see the JRuby JSON options
become competitive with the fastest MRI + C options, but it would take
some work.