Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-5152

Bean merger mechanism is not performant due to missing caching of values

    XMLWordPrintable

Details

    Description

      We use now the proxy based bean merger but build again and again such proxy objects. I quickly improved the info.magnolia.beanmerger.ProxyBasedBeanMerger by adding value caching.

      
             @Override
              public Object invoke(Object proxy, Method method, Object[] arguments) throws Throwable {
              	// only merge calls to property getters
                  if (arguments.length > 0) {
                      // invoke the method on the first possibility
                      for (Object source : sources) {
                          if(method.getDeclaringClass().isInstance(source)){
                          	if(method.getName().startsWith("set")){
                          		String getterMethodName = "get" + StringUtils.removeStart(method.getName(),"set");
                          		cache.remove(getterMethodName);
                          	}
                              return method.invoke(source, arguments);
                          }
                      }
                      throw new IllegalStateException("Can't call method " + method.getName() + " on any of the sources.");
                  }
      
                  // try to use cache
                  if(cache.containsKey(method.getName())){
                  	return cache.get(method.getName());
                  }
      
                  List values = new ArrayList();
                  for (Object obj : sources) {
                      values.add(evaluate(obj, method, arguments));
                  }
      
                  Object merged = merger.merge(values);
                  cache.put(method.getName(), merged);
                  return merged;
              }
      

      Checklists

        Acceptance criteria

        Attachments

          Activity

            People

              mdivilek Milan Divilek
              pbaerfuss Philipp Bärfuss
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Checklists

                  Bug DoR
                  Task DoD