Details
-
Type:
Improvement
-
Status: Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.13 M1 (Ingalls)
-
Component/s: Core
-
Labels:
-
Pull Request URL:
-
Sprint:Hopper SR2
Description
The linked answer on StackOverflow seems to indicate that statically held MethodHandle instances are more than twice as fast as a reflective getting and setting of fields. We should investigate whether we could provide an alternative to the BeanWrapper implementation that uses ASM to generate a PropertyAccessor implementation for a type with the method handles for properties held in static final fields and an if-then-else cascade to select invoke the right one for a given PersistentProperty.
final class $PersistentEntityPropertyAccessor implements PropertyAccessor { // For each field/getter private static final MethodHandle $memberGetHandle; // property.useFieldAccess() ? MethodHandles.lookup().unreflectGetter(field) : MethodHandles.lookup().unreflect(getter); private static final MethodHandle $memberSetHandle; // property.useFieldAccess() ? MethodHandles.lookup().unreflectGetter(field) : MethodHandles.lookup().unreflect(setter); private final Object bean; @Override public Object getProperty(PersistentProperty<?> property) { String name = property.getName(); if (name == "foo") { return fooGetHandle.invoke(bean); } … } @Override public void setProperty(PersistentProperty<?> property, Object value) { String name = property.getName(); if (name == "foo") { return fooSetHandle.invoke(bean, value); } … } }