Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
-
None
Description
AtmosphereEventSubscriptionCollector.onBeforeRender() is called so often that the amount of work it performs starts being significant. The method was a hotspot in our performance tests. I reduced the average HTTP response time by 20ms by caching the subscribe metods:
private static final ConcurrentMap<Class<?>, List<Method>> class2SubscribeMethod = new ConcurrentHashMap<Class<?>, List<Method>>();
@Override
public void onBeforeRender(Component component)
{
for (Method curMethod : getSubscribeMethods(component.getClass()))
for (Behavior curBehavior : component.getBehaviors())
{
for (Method curMethod : getSubscribeMethods(curBehavior.getClass()))
}
}
private List<Method> getSubscribeMethods(Class<?> clazz)
{
List<Method> methods = class2SubscribeMethod.get(clazz);
if (methods != null)
methods = computeSubscribeMethods(clazz);
List<Method> newMethods = class2SubscribeMethod.putIfAbsent(clazz, methods);
return newMethods != null ? newMethods : methods;
}
private List<Method> computeSubscribeMethods(Class<?> clazz)
{
List<Method> result = Lists.newArrayList();
for (Method curMethod : clazz.getMethods())
{
if (curMethod.isAnnotationPresent(Subscribe.class))
}
return result;
}
I can provide a patch of a pull request if needed.