0

I ported the Java code of the Havlak benchmark from Robert Hundt (see link) to Groovy. Now I run the benchmark with Groovy 2.1.1 with invoke dynamic and without, but the duration the computation takes is almost the same. What did I do to enable invoke dynamic? I copied the groovy--indy.jars from groovy-2.1.1\indy to groovy-2.1.1\lib. Then I deleted in groovy-2.1.1\lib all the groovy.jars wihtout "indy" in their name. Thereafter, in IntelliJ IDEA I enabled and disabled the flag File > Settings > Compiler > Groovy Compiler > Invoke dynamic support.

I'm just telling this to make people see whether I turned on indy support correctly. But this is not my question. My question is in what kind of situations can we expect a speed up in computation time, because of invoke dynamic. I read articles about it, but it is hard to translate what is explained there about what invoke dynamic does into some statement that "this kind of code will execute faster with indy support". The Havlak benchmark does a lot of looping where values are changed through calling setters.

I'd be glad if anyone having some understanding of the matter would drop some explanations here :-).

Thanks, Oliver

OlliP
  • 1,545
  • 11
  • 22

2 Answers2

1

I think the mainly speedup of invokedynamic would be when you use some kind of duck typing.

The invokedynamic API is made for languages with dynamic method dispatch on the JVM. Groovy certainly is one of those. But it can only make use of indy, if you use a method with dynamic dispatch. I can give you an example, if you need one.

However I have analyzed the indy dispatch functionality in Groovy and it seems like it only packed the old dynamic dispatch function into its methodhandles. In fact, if it really does so, it can't be faster. In my perception the Groovy implementation of invokedynamic isn't optimized at the moment.

Thorben
  • 953
  • 13
  • 28
  • Groovy is always doing dynamic dispatch, unless the primitive optimizations path is taken, which is only done under specific conditions that can be influenced at runtime. – blackdrag Mar 07 '13 at 09:40
  • Yes it always does dynamic dispatch. What I ment is invokedynamic can only speedup the execution, if you use a method multiple times. Okay that's the normal case in almost every program, but it – Thorben Mar 15 '13 at 12:02
  • should be considered. The speedup happens when the call was bootstraped and is linked to a comiled MethodHandle. Then you can reuse the MethodHandle until something changes. Without indy and without caching techniques in the implementation of the script language etc. the dispatch would happen for every single method call. Perhaps this helps. – Thorben Mar 15 '13 at 12:13
  • Since I think Groovy 1.6 Groovy has already a call site caching implementation. It is based on runtime generated classes and some reflection. So the reuse case was already possible before. – blackdrag Mar 20 '13 at 15:28
0

short answer: use a category. If your code does gets much slower when using it, then you are not using indy.

longer answer: if you could post the code somewhere I could analyze it

blackdrag
  • 6,413
  • 2
  • 26
  • 38