diff options
author | Leif Åstrand <leif@vaadin.com> | 2015-07-08 10:44:35 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-07-11 13:30:23 +0000 |
commit | 2564627fed188600e8e0925a9865481db39ffee7 (patch) | |
tree | 1f3e6def50db0a2450b74883610cf6a4c43ab939 /server | |
parent | 16a00beddef02cdc37bbeb41f34a3e3d2edf17bc (diff) | |
download | vaadin-framework-2564627fed188600e8e0925a9865481db39ffee7.tar.gz vaadin-framework-2564627fed188600e8e0925a9865481db39ffee7.zip |
Cache connector state types (#18437)
Reduces time spent in findStateType() for the "40 layouts" action in
BasicPerformanceTest from around 2 ms to around 0.2 ms. This improves
the total performance of the action by about 5%.
Change-Id: I4f979827b2da0d4db87e201fa78421e5551a4113
Diffstat (limited to 'server')
-rw-r--r-- | server/src/com/vaadin/server/AbstractClientConnector.java | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/server/src/com/vaadin/server/AbstractClientConnector.java b/server/src/com/vaadin/server/AbstractClientConnector.java index 0655b482ed..b6bcebd167 100644 --- a/server/src/com/vaadin/server/AbstractClientConnector.java +++ b/server/src/com/vaadin/server/AbstractClientConnector.java @@ -30,6 +30,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; +import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; import com.vaadin.event.EventRouter; @@ -91,6 +92,8 @@ public abstract class AbstractClientConnector implements ClientConnector, private ErrorHandler errorHandler = null; + private static final ConcurrentHashMap<Class<? extends AbstractClientConnector>, Class<? extends SharedState>> stateTypeCache = new ConcurrentHashMap<Class<? extends AbstractClientConnector>, Class<? extends SharedState>>(); + @Override public void addAttachListener(AttachListener listener) { addListener(AttachEvent.ATTACH_EVENT_IDENTIFIER, AttachEvent.class, @@ -296,7 +299,12 @@ public abstract class AbstractClientConnector implements ClientConnector, // Lazy load because finding type can be expensive because of the // exceptions flying around if (stateType == null) { - stateType = findStateType(); + // Cache because we don't need to do this once per instance + stateType = stateTypeCache.get(this.getClass()); + if (stateType == null) { + stateType = findStateType(); + stateTypeCache.put(this.getClass(), stateType); + } } return stateType; |