You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by jw...@apache.org on 2011/02/09 18:40:29 UTC
svn commit: r1068990 -
/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
Author: jwaldman
Date: Wed Feb 9 17:40:29 2011
New Revision: 1068990
URL: http://svn.apache.org/viewvc?rev=1068990&view=rev
Log:
TRINIDAD-2032 perf: save memory by sharing selector objects in filesystemstylecache
Modified:
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java?rev=1068990&r1=1068989&r2=1068990&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java Wed Feb 9 17:40:29 2011
@@ -310,6 +310,7 @@ public class FileSystemStyleCache implem
_entryCache = null;
_document = null;
_reusableStyleMap = null;
+ _reusableSelectorMap = null;
_shortStyleClassMap = null;
_namespacePrefixes = null;
}
@@ -327,6 +328,8 @@ public class FileSystemStyleCache implem
_entryCache = new ConcurrentHashMap<Object, Entry>(19);
if (_reusableStyleMap == null)
_reusableStyleMap = new ConcurrentHashMap<Style, Style>();
+ if (_reusableSelectorMap == null)
+ _reusableSelectorMap = new ConcurrentHashMap<Selector, Selector>();
cache = _cache;
entryCache = _entryCache;
@@ -460,7 +463,20 @@ public class FileSystemStyleCache implem
Style style = _convertStyleNodeToStyle(styleNodes[i], _reusableStyleMap);
if (resolvedSelectorStyleMap == null)
resolvedSelectorStyleMap = new ConcurrentHashMap<Selector, Style>();
- resolvedSelectorStyleMap.put(Selector.createSelector(selector), style);
+
+ // To save memory, we reuse Selector objects
+ Selector selectorCreated = Selector.createSelector(selector);
+ Selector cachedSelector = _reusableSelectorMap.get(selectorCreated);
+ if (cachedSelector == null)
+ {
+ _reusableSelectorMap.put(selectorCreated, selectorCreated);
+ resolvedSelectorStyleMap.put(selectorCreated, style);
+ }
+ else
+ {
+ resolvedSelectorStyleMap.put(cachedSelector, style);
+ }
+
}
}
@@ -1521,6 +1537,11 @@ public class FileSystemStyleCache implem
* FileSystemStyleCache$Entry instance. The is the map we use to store unique Style objects. */
private ConcurrentMap<Style, Style> _reusableStyleMap;
+ /** Use this to store Selector objects so that they can be reused in all the FileSystemStyleCache$StylesImpl
+ * objects. A generated css file can contain 4533 selectors at 16 bytes each. The Selectors will largely
+ * be the same between FileSystemStyleCache$StylesImpl instances, so they should be shared. */
+ private ConcurrentMap<Selector, Selector> _reusableSelectorMap;
+
/** The cache of style sheet URIs */
private ConcurrentMap<Key, Entry> _cache;