diff options
author | Leif Åstrand <leif@vaadin.com> | 2015-07-08 10:44:35 +0300 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-07-21 14:40:22 +0300 |
commit | 40485eb3afca72e53eccd5b8905fa193bb8a03b4 (patch) | |
tree | f9297ef6aa1ff88b3d1d24ced2a5779ff0b8c652 | |
parent | 258b2cf2272ec53193c3474a072e21b78c94ef27 (diff) | |
download | vaadin-framework-40485eb3afca72e53eccd5b8905fa193bb8a03b4.tar.gz vaadin-framework-40485eb3afca72e53eccd5b8905fa193bb8a03b4.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: I4b32c6530089400a616c62400cb2f282f0caa62c
-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; |