How is Groovy performance compared to Java?

What is Groovy performance compared to Java?

+47
java groovy
Mar 08 2018-11-11T00:
source share
7 answers

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.

+48
Mar 08 2018-11-11T00:
source share

So, here we are in 2012, and Groovy 2.0 is ready to rock and roll ...

"With @CompileStatic, Groovy's performance is about 1-2 times slower than Java, and without Groovy, it's about 3-5 times slower. (...) This means that Groovy is ready for applications whose performance should be somewhat comparable with Java.

Performance Test: Groovy 2.0 vs. Java http://java.dzone.com/articles/groovy-20-performance-compared

And besides the author, I used Groovy since 2008 with great success, and not just for CV, just to get the job done at the right time. Performance is always relative to what you want to do.




For those who complain about numeric use cases, this uses a real use case using web frameworks: http://www.jtict.com/blog/rails-wicket-grails-play-lift-jsp/




"Groovy 1.8.x prototype for fib (42) takes about 3.8 s ( just 12% slower than Java, a hundred times faster than Groovy 1.0 ). Therefore, we cannot encourage people to write such for longer." hotspots in Java.

Source: http://www.wiki.jvmlangsummit.com/images/0/04/Theodorou-Faster-Groovy-1.8.pdf

"I'm impressed with how much Groovyโ€™s performance has improved for numerical computing. Groovy 1.8 in my jlab project (http://code.google.com/p/jlabgroovy/) sometimes outperforms Scala in my other ScalaLab project (http: // code .google.com / p / scalalab) !! "

Source: http://groovy.329449.n5.nabble.com/Great-improvements-in-Groovy-s-performance-for-numerical-computing-td4334768.html

+17
May 15 '11 at 7:22 a.m.
source share

Groovy offers a lot more syntactic sugar over Java, but still runs on the JVM, and so the JVM needs a bit more work to provide that sugar. However, in the vast majority of ordinary customs, the difference is very small.

Also, if you are lucky enough to write a function that runs too slowly in Groovy, you can write it in direct Java and call it from your Groovy code. That the team recommended a solution, and I can guarantee that it works well and simply.

This is my opinion, for most programmers, this is not a problem.

+8
Mar 08 '11 at 22:00
source share

A quick Google search yielded some old results ( http://www.codecommit.com/blog/java/groovys-performance-is-not-subjective , http://www.christianschenk.org/blog/performance-comparison-between -groovy-and-java / ).

Groovy ++ is also interesting ( http://stronglytypedblog.blogspot.com/2010/02/java-vs-scala-vs-groovy-vs-groovy.html ).

However, the reason for using Groovy should be that it improves your performance, not computers ...

+7
Mar 08 2018-11-11T00:
source share

Generally speaking, Groovy will be slower. You can avoid this by switching to Groovy ++, which offers most Groovy features, but can be statically compiled and has performance comparable to Java.

+2
Mar 08 '11 at 10:11
source share

I think you should look at this scientific comparison of Groovy Vs Python Vs PHP vs Ruby.

http://blog.websitesframeworks.com/2013/11/comparison-of-programming-languages-ruby-groovy-python-and-php-353/

They did one exercise and made comparisons in these programming languages โ€‹โ€‹on the following factors:

Comparison of time developing each exercise Comparison of readability of the languages Comparison of results in benchmarks and lines of code. From the project Computer Language Benchmarks Game Conclusions 

This is an excellent quick study, allowing you to better understand the language.

+2
Oct 30 '15 at 18:32
source share

Groovy is compiled into bytecode .class files, but ~ 5MB Groovy library is required to execute Groovy classes, which costs performance.

-12
Mar 09 '11 at 9:53
source share



All Articles