Event4J
Event4J copied to clipboard
Improve MethodHandle performance
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.
Any test code and benchmark to shown performance parity with ASM executors?
Not yet :(