« Consumer JRE - I think they may have pulled it off. | Main | Greet - A Groovy Twitter Client »

Groovy Faster than Ruby? Apparently.

I kind of brushed over Alex's speed improvements in the recent Groovy 1.6-beta1 release, but based on some recent benchmarks it looks like it needs some re-iterating. Alex implemented something called call site caching. Here's what goes on. When we encounter a call site we look at some notes we left the last time we ran through it, (assuming there are any). We compare notes, and if nothing changed, we don't recalculate the MOP dispatch and just do what we did last time. If our notes are different, we do the full MOP dispatch over again. It's the 'memento' design pattern. Charles Oliver Nutter has a great writeup on how this works. I thought it would speed things up, but I was suprised by how much.

Consider these external numbers from The Computer Language Benchmarks Game. Left is the comparison implementation, right is Groovy. White is speed, black is memory consumption. Measures are relative to each other.

First, JRuby 1.1. (Note: JRuby 1.1.1, wasn't on the alioth site)

This surprised me. Charles Oliver Nutter has been working intently on making the JRuby call sites work very well with the HotSpot optimizations. Lots of talk about monomorphic branch paths, reflection barriers, and other stuff that makes my head hurt like I'm back in my undergraduate algorithms class. Groovy beat JRuby in most of the tests (it used to be all but one, but it looks like possibly it got the JRuby 1.1.1 update). I'm not sure why however. Possibly better loop optimizations.

I remember that Charles was excited that some JRuby benchmarks had been running faster than Ruby, and that it was running Rails faster, some I compared Groovy against Ruby 1.8.6.

The first two places Ruby beast groovy are not surprising, calculating the digits of Pi and regular expression searching of DNA sequences. The last on we get spanked on, printing hello world. This is partly because the way the test is set up groovy both compiles and executes the test, then there is plain old jvm startup time, even plain old Java loses to Ruby in that one. There is also the issue of memory consumption. Generally speaking Ruby has a better story when it comes to these benchmarks.

Ruby gains some ground when using the YARV vm in Ruby 1.9, but Groovy still maintains a performance edge, while getting beat on memory for the most part.

Now I am not claiming that Groovy is the most performant language on the JVM, it isn't. But it's performance story has improved markedly. Since groovyc can jointly compile plain old java (which is slightly faster than Scala) it provides a nice fallback for performance intensive parts that are critical.

Now it's time to pack for JavaOne.

Update: Some of the analysis is off because some of the groovy programs that are missing are being filled in as time goes on. Some of these are as partial sums and reverse complement (which Groovy stinks at apparently) and more (like k-nucleotide) are to come. I am also directly linking to their images, so as the other implemetnations get updated, the images will change.


This page contains a single entry from the blog posted on May 4, 2008 9:13 AM.

The previous post in this blog was Consumer JRE - I think they may have pulled it off..

The next post in this blog is Greet - A Groovy Twitter Client.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33