speed of invokeExact
Jochen Theodorou
blackdrag at gmx.org
Wed May 8 05:33:58 PDT 2013
Am 07.05.2013 19:31, schrieb Christian Thalinger:
[...]
> Do you have any numbers?The problem is that if the MH is not constant
> we can't do any inlining and it will be an out-of-line call (with a trampoline in between). Is
> your DMH a static or virtual?
arg... looks like I made a mistake. It is not the invokeExact that is
slow, it is my preparation of the handle that is slow.
I get the arguments as Object[] so I do:
> MethodHandle mh =
call.target.asSpreader(Object[].class, call.args.length);
> mh = MethodHandles.insertArguments(mh, 0, call.receiver);
> mh = mh.asType(VC);
I found this code doesn't really make sense in my case, since the
arguments length is 0. But even if I replace it by
> MethodHandle mh = MethodHandles.dropArguments(call.target, 1, Object[].class);
> mh = MethodHandles.insertArguments(mh, 0, call.receiver);
> mh = mh.asType(VC); //VC= Object[]:Object
it takes long. It improved in my test from 15000 to 3000. The only
problem is that my old way still takes only a fraction of that. In 3000
I can not only do the invocation plus adaption for the call, I can even
do full method selection... and it still totals to only about 200. And
of that 3000 an estimated 2900 goes into adapting the handle.
Now I am a bit unsure of how to get this better. The problem is that I
have such an invokeExact path in Groovy today already. It is called the
first time the handle is selected and in case of a callsite that does
not cached, or that got invalidated. In a typical microbenchmark that
situation may not appear often, but in a general application it does.
In further experiments I used spreadInvoker, which did help to get times
down to 1500
> MethodHandle mh = MethodHandles.spreadInvoker(call.target.type(), call.args.length+1);
> mh = mh.asType(VC) //VC= MethodHandle,Object,Object[]:Object
but I cannot get rid of the asType call in my generic code. If I use
casts to force the right types and don't use asType I get about 250
bye blackdrag
--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org
More information about the mlvm-dev
mailing list