I wrote a little benchmark that tests performance of java.lang.invoke.MethodHandle
, java.lang.reflect.Method
and direct calls of methods.
I re
Looks like this was indirectly answered by @AlekseyShipilev in reference to a different query. In the following link How can I improve performance of Field.set (perhap using MethodHandles)?
If you read through you will see additional benchmarks that show similar findings. It is likely that direct calls can simply be optimized by JIT in ways that According to the findings above, the difference is:
So - direct calls will still be faster, but MH is very fast. For most use-cases this should be sufficient and is certainly faster than the old reflection framework (btw - according to the findings above, reflection is also significantly faster under java8 vm)
If this difference is significant in your system, i would suggest finding different patterns rather than direct reflection which will support direct calls.