On 01/12/2017 03:23 PM, Stephen Colebourne wrote:
> The real problem however is performance. In my tests, I am seeing a
> MethodHandle approach being 2 to 3 times slower than a reflection
> approach for identical functionality, which is quite a significant
> degradation. (using Java 8 b122)

MethodHandle performance depends heavily on whether compiler is able to constant
fold its internals. Putting MHs into "static final"-s should do this. In your
code, I see at least two places where MHs are not constant:

+    /** The constructor to use. */
+    private final MethodHandle constructor;

+    /** The read method. */
+    private final MethodHandle getter;

Still, even the non-constant MH invoke should be faster than reflection, because
it does not have to check permissions on invoke. See the tests here, these can
be extended for your interesting cases, including setAccessible(true):
  http://stackoverflow.com/a/22337726


Thanks,
-Aleksey

Reply via email to