Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Java-style Groovy as fast as Java?

If I understand correctly Groovy is dynamically typed but since it's almost a superset of Java, static type information may optionally be provided. This could be useful if writing something where only a few parts are performance critical while avoiding the friction of using multiple languages. Type annotations could be provided only for the performance critical parts.

What is the performance penalty for using Groovy instead of Java in functions/classes where the Java-like subset is used and static type annotations are provided?

like image 284
dsimcha Avatar asked Sep 05 '11 00:09

dsimcha


1 Answers

Declaring types in groovy doesn't magically speed things up. It's still groovy code and needs to go through the MOP in case something got dynamically changed. You don't get static linking just because you've given type information.

For performance sensitive things that the groovy code just isn't fast enough for, you'll need to write real java code.

This question is very similar to a previous one where I gave an answer digging into the generated byte code showing how typing something doesn't speed things up.

like image 73
Ted Naleid Avatar answered Oct 12 '22 15:10

Ted Naleid