How much will JSR-292 (invokedynamic) do to Groovy performance?
Asked Answered
B

4

9

Is there an estimate that says how much JSR-292 will impact Groovy performance?

Bailar answered 6/1, 2010 at 6:1 Comment(2)
Looks like there's still a long way to go for Groovy code to get certain performance benefit from invokedynamic. My genetic algorithm performed 5 times slower with invokedynamic enabled, and I tested it with Java 1.8.0 and Groovy 2.2.1! You can try for yourself, just clone this: github.com/renatoathaydes/MachineLearning and run test com.athaydes.ml.algorithms.LinearGPTest::testNonTrivialPrograms. It runs in 4 seconds normally, but with groovy-indy and invokedynamic, it runs in at least 25 seconds.Xhosa
Another post which also showed indy can actually slow down your Groovy code: derjan.io/blog/2012/08/08/…Xhosa
W
4

invokedynamic is a complicated story really, since the performance characteristics changes all the time in JDK7. During porting Groovy to indy I got really, really near Java, about factor 1.5. But I have to use the catchExceptionGuard, which reduces performance to something like being factor 3-4. We still need to investigate ways to avoid having to use that guard. Maybe we will have to break some existing code in Groovy 2.2 for that. Anyway, I don't need the guard for the invokeMethod fallback as mentioned above. It is for GroovyRuntimeExceptions possibly containing other exceptions, that I have to unwrap or do other things with. So the theoretical possible performance seems to be between Java and half of Java speed for existing methods. Performance of calls to invokeMethod is a whole different story.

If you need more, then use @CompileStatic in Groovy 2.0.

Wirth answered 16/1, 2013 at 13:40 Comment(0)
M
3

I don't think there is a benchmark yet, and until someone performs it we can only guess...

You may find this post in this matter interesting.

Mugwump answered 6/1, 2010 at 6:14 Comment(0)
D
2

It would be around 10-50 times faster in general.

http://www.mail-archive.com/[email protected]/msg00819.html

Devoted answered 6/1, 2010 at 13:57 Comment(3)
Can you please back that up with some references or evidence?Bias
Hi, I have added the link. It's based on my own experience of creating a Groovy compiler over JSR-292. And basically, it's an estimation (as the question has asked for the estimation as well ;)Devoted
Really misleading. I actually got a 5x slowdown with indy enabled.Xhosa
G
0

I'm not sure how much is it applicable to Groovy. If I remember well, Groovy has some fallbacks (e.g. invokeMethod method). It is not possible to simply use the fallback with invokedynamic, I think.

However, there are some ways:

  • Catch the exception that is thrown when the method is not found. Unfortunately, it is probably necessary to analyze stacktrace, because you can't be sure where is it thrown from. This can be a signifficant slowdown when calling a non-existing method, regardless it is handled by invokeMethod callback.
  • Look at Groovy++. It allows you to use static typing if you satisfy some contraints. In such case, the it can be possible to allow you to switch to a "strict dynamic mode", which does not allow these fallbacks.
Garay answered 30/4, 2011 at 9:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.