Uploaded image for project: 'Spring Data Commons'
  1. Spring Data Commons
  2. DATACMNS-809

Investigate use of method handles for property access

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.13 M1 (Ingalls)
    • Component/s: Core
    • Labels:

      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);
          } …
        }
      }
      

        Attachments

          Activity

            People

            • Assignee:
              mp911de Mark Paluch
              Reporter:
              olivergierke Oliver Drotbohm
              Last updater:
              Oliver Drotbohm
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: