Event4J icon indicating copy to clipboard operation
Event4J copied to clipboard

Improve MethodHandle performance

Open Techcable opened this issue 9 years ago • 2 comments

MethodHandle performance is currently bad, even slower than reflection. I think this is because we use MethodHandle.invoke() instead of MethodHandle.invokeExact(), which has to do a lot of type checks and type-conversions.

However, we can't call invokeExact with plain object arguments unless the method accepts object arguments. To fix this, we need to convert the MethodHandle to accept object arguments (casting internally), by using handle.asType(MethodType.genericMethodType(2)). This will let us switch to invokeExact() and eliminate a lot of performance overhead.

We also should investigate MethodHandle.bindTo() for 'binding' the MethodHandle to the specific listener we're invoking. This allows the JVM to choose to the correct method when the MethodHandle is created, instead of when it's invoked.

Hopefully this will let MethodHandles achieve performance parity with ASM executors, without the overhead of the generation.

Techcable avatar Jul 31 '16 22:07 Techcable

Any test code and benchmark to shown performance parity with ASM executors?

caoli5288 avatar Aug 17 '16 03:08 caoli5288

Not yet :(

Techcable avatar Aug 17 '16 15:08 Techcable