Is Groovy 60 Times Slower than Java?
(In a word, no!)
In a pair of very intriguing postings (here and here), Tiago details what he has been observing about the comparative performance of Groovy and Java. He is thorough and probing in his attempts to speed up the Groovy performance, and he lays out a detailed line-by-line analysis of where the code is actually spending time in his tests. Tiago makes some excellent points.
1. Language performance is highly overrated
Much is often made of the theoretical "performance" of a language based on benchmarks and arcane tests. There have even been cases where vendors have built cheats into their products specifically so they would score well on benchmarks. In the end, runtime execution speed is not as important a factor as a lot of people would think it is if they only read about performance comparisons. Other factors such as maintainability, interoperability, developer productivity and tool and library support are all very significant, too.
2. In Groovy, the sensitive parts can always be written in Java
Not much to explain here. When you're working in Groovy you always have the full power of the underlying Java platform and language at your fingertips. If you find a bit of your Groovy code is going slower than you'd like, then you can easily drop to Java and see whether that affords the speedup you want.
3. By successive refinement, performance can be optimized
After his original blog posting Tiago received some good insights about how to use idiomatic expressions to get better performance results from his Groovy test code. He shows quite clearly how one change shaved off a full minute, and another shaved 1m10s. He's actually gotten it down to where Groovy now takes only 90s compared to Java's 4s. It's still a good deal slower, but a lot faster than when he started.
Anyway, I really admire this type of explicit analysis and documented experimentation to improve results. IMO, Tiago has done a really good job trying to zero in on where performance differences exist and how they can potentially be narrowed. One of the things I find most interesting here is that the shoe is really on the other foot now! How many years were we reading people's subjective (and usually unscientific) criticism of Java performance in comparison to their language of preference? Now we see Java as the speed reference. You've come a long way, baby!
What are your own observations about the comparative performance of Groovy and Java? Does performance (in this way) matter to you? What tools and techniques have you found useful to improve performance?