[MAGNOLIA-5152] Bean merger mechanism is not performant due to missing caching of values Created: 03/Jul/13 Updated: 08/Jul/13 Resolved: 08/Jul/13 |
|
| Status: | Closed |
| Project: | Magnolia |
| Component/s: | rendering |
| Affects Version/s: | 4.5.9, 5.0 |
| Fix Version/s: | 4.5.10, 5.0.1 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Philipp Bärfuss | Assignee: | Milan Divilek |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | performance, rendering | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Template: |
|
||||
| Acceptance criteria: |
Empty
|
||||
| Task DoD: |
[ ]*
Doc/release notes changes? Comment present?
[ ]*
Downstream builds green?
[ ]*
Solution information and context easily available?
[ ]*
Tests
[ ]*
FixVersion filled and not yet released
[ ] 
Architecture Decision Record (ADR)
|
||||
| Bug DoR: |
[ ]*
Steps to reproduce, expected, and actual results filled
[ ]*
Affected version filled
|
||||
| Date of First Response: | |||||
| 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;
}
|
| Comments |
| Comment by Magnolia International [ 04/Jul/13 ] |
|
Please add an inline comment explaining what looks like a workaround - if (method.getName().startsWith("set")) |
| Comment by Magnolia International [ 04/Jul/13 ] |
|
See comment above. Also git commit message could have been a little (read: a lot) more explicit |