Obviously, Groovy compiles in the JVM. This, however, has little to do with performance.
The most important thing to note here is that Groovy is a dynamic language. This essentially means that most of the time the Groovy compiler will have little knowledge about the type of object that it invokes the method on / retrieving the property. This has a huge impact on performance. There are thousands of different classes that implement someFancyMethodName () without a common base class. However, calling obj.someFancyMethodName () should select the correct one. There is no better way to do this than to solve it at runtime based on some kind of reflection. In fact, because of this, every method call is dispatched via an invokeMethod () call on the object's metaclass. This is very noticeable in stacktraces if your program ever throws some nasty exceptions. This is even worse. Any class in Groovy can propose dynamically implementing implementations of methods of a given name that produce them at runtime. There is an enormous amount of Grails magic that makes great use of it. Another complication arises when the method is overloaded. Since type knowledge is so limited, it is not possible to select the correct version of a method at compile time. The generated code should look at the supplied objects, and then, creating the if-elses series, selects the implementation that best suits the provided call. In most cases, this is a truly non-trivial process that should never be executed at run time. However, Groovy must do this in order to remain Java compatible.
Everything that makes Groovy pretty slow. Actually much slower and, more painfully, more memory than most dynamic languages โโ(e.g. Python).
However, I agree that the reason for using Groovy is certainly not performance. In most cases, you end up optimizing only a small part of your code. If performance is such a problem, you can always resort to rewriting these specific parts in pure Java or try Groovy ++. I have not tried this myself, however, the results that I read about online looked pretty promising.
Groovy 2.0 I do not have experience with a newer version. Honestly, I am no longer an active user of Groovy. Nevertheless, I would expect that most of the problems described above are fundamentally complex and require a major scientific breakthrough. I have experience developing HHVM (a PHP virtual machine created by Facebook), and there are much simpler functions that performed poorly.
julkiewicz Mar 08 2018-11-11T00: 00Z
source share