MethodHandle.invoke* performance
Cédric Champeau
cedric.champeau at gmail.com
Wed Apr 3 08:03:09 PDT 2013
Hi guys,
First of all, sorry if my question looks stupid, but I have difficulties
explaining what I see. I made a small benchmark for various
MethodHandle.invoke* combinations. Of course, micro-benchmarks are evil,
but in that case, I find the figures quite interesting. Note that I'm
not using invokedynamic instructions anywhere, I'm just "testing" the
API from plain Java. As MethodHandles are promoted as "faster than
reflection", I expected very different results.
So first, the link: https://gist.github.com/melix/5291792
The results I obtain here with openjdk-8-lambda b83 are not good:
|Classic for loop[-1] 166ms||
||InvokeExact[-1] 170ms||
||InvokeExact (local method handle)[-1] 3410ms||
||bindTo+invokeExact[-1] 6905ms||
||insertArgument+invokeExact[-1] 6254ms||
||invoke[-1] 60118ms||
||bindTo+invoke[-1] 80072ms||
||insertArgument+invoke[-1] 78337ms||
||Reflect[-1] 1219ms||
|
I added the "static final field" version as a suggestion from Jochen
Theodorou, and it does make things much faster, but it's the *only* case
that comes close to regular Java performance. Any other combination is
much slower. I know that invoke() is supposed to perform type
conversions, but is it supposed to be that slow as compared to
invokeExact? What explains the difference between the local method
handle and the static field version? In theory, using invokedynamic
instruction, the method handle would come from a boostrap method so I
could expect the same performance as the static field version, but if
any other combination than direct invokeExact calls are slower, then
it's not good. So, basically, I'd like to know what I'm missing here :)
Thanks for your explanations!
P.S: Note that order of tests do not matter here, I know I should not
mix things, but I tested with different test execution order without
more success.
--
Cédric Champeau
SpringSource - A Division Of VMware
http://www.springsource.com/
http://twitter.com/CedricChampeau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/mlvm-dev/attachments/20130403/af9d36fa/attachment.html
More information about the mlvm-dev
mailing list