Title: [143348] trunk/Source/_javascript_Core
Revision
143348
Author
gga...@apple.com
Date
2013-02-19 09:48:15 -0800 (Tue, 19 Feb 2013)

Log Message

Save space on keys in the CodeCache
https://bugs.webkit.org/show_bug.cgi?id=110179

Reviewed by Oliver Hunt.

Share the SourceProvider's string instead of making our own copy. This
chops off 16MB - 32MB from the CodeCache's memory footprint when full.
(It's 16MB when the strings are LChar, and 32MB when they're UChar.)

* runtime/CodeCache.cpp:
(JSC::CodeCache::getFunctionExecutableFromGlobalCode):
* runtime/CodeCache.h: Removed a defunct enum value.

(JSC::SourceCodeKey::SourceCodeKey):
(JSC::SourceCodeKey::isHashTableDeletedValue):
(SourceCodeKey):
(JSC::SourceCodeKey::hash):
(JSC::SourceCodeKey::length):
(JSC::SourceCodeKey::isNull):
(JSC::SourceCodeKey::string):
(JSC::SourceCodeKey::operator==): Store a SourceCode instead of a String
so we can share our string with our SourceProvider. Cache our hash so
we don't have to re-decode our string just to re-hash the table.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (143347 => 143348)


--- trunk/Source/_javascript_Core/ChangeLog	2013-02-19 17:42:55 UTC (rev 143347)
+++ trunk/Source/_javascript_Core/ChangeLog	2013-02-19 17:48:15 UTC (rev 143348)
@@ -1,3 +1,29 @@
+2013-02-18  Geoffrey Garen  <gga...@apple.com>
+
+        Save space on keys in the CodeCache
+        https://bugs.webkit.org/show_bug.cgi?id=110179
+
+        Reviewed by Oliver Hunt.
+
+        Share the SourceProvider's string instead of making our own copy. This
+        chops off 16MB - 32MB from the CodeCache's memory footprint when full.
+        (It's 16MB when the strings are LChar, and 32MB when they're UChar.)
+
+        * runtime/CodeCache.cpp:
+        (JSC::CodeCache::getFunctionExecutableFromGlobalCode):
+        * runtime/CodeCache.h: Removed a defunct enum value.
+
+        (JSC::SourceCodeKey::SourceCodeKey):
+        (JSC::SourceCodeKey::isHashTableDeletedValue):
+        (SourceCodeKey):
+        (JSC::SourceCodeKey::hash):
+        (JSC::SourceCodeKey::length):
+        (JSC::SourceCodeKey::isNull):
+        (JSC::SourceCodeKey::string):
+        (JSC::SourceCodeKey::operator==): Store a SourceCode instead of a String
+        so we can share our string with our SourceProvider. Cache our hash so
+        we don't have to re-decode our string just to re-hash the table.
+
 2013-02-19  Zoltan Herczeg  <zherc...@webkit.org>
 
         revertBranchPtrWithPatch is incorrect on ARM traditional

Modified: trunk/Source/_javascript_Core/runtime/CodeCache.cpp (143347 => 143348)


--- trunk/Source/_javascript_Core/runtime/CodeCache.cpp	2013-02-19 17:42:55 UTC (rev 143347)
+++ trunk/Source/_javascript_Core/runtime/CodeCache.cpp	2013-02-19 17:48:15 UTC (rev 143348)
@@ -105,7 +105,7 @@
 
 UnlinkedFunctionExecutable* CodeCache::getFunctionExecutableFromGlobalCode(JSGlobalData& globalData, const Identifier& name, const SourceCode& source, ParserError& error)
 {
-    SourceCodeKey key = SourceCodeKey(source, name.string(), SourceCodeKey::FunctionCallType, JSParseNormal);
+    SourceCodeKey key = SourceCodeKey(source, name.string(), SourceCodeKey::FunctionType, JSParseNormal);
     const Strong<JSCell>* result = m_sourceCode.find(key);
     if (result)
         return jsCast<UnlinkedFunctionExecutable*>(result->get());

Modified: trunk/Source/_javascript_Core/runtime/CodeCache.h (143347 => 143348)


--- trunk/Source/_javascript_Core/runtime/CodeCache.h	2013-02-19 17:42:55 UTC (rev 143347)
+++ trunk/Source/_javascript_Core/runtime/CodeCache.h	2013-02-19 17:48:15 UTC (rev 143348)
@@ -55,44 +55,51 @@
 
 class SourceCodeKey {
 public:
-    enum CodeType { EvalType, ProgramType, FunctionCallType, FunctionConstructType };
+    enum CodeType { EvalType, ProgramType, FunctionType };
 
     SourceCodeKey()
-        : m_flags(0)
     {
     }
 
     SourceCodeKey(const SourceCode& sourceCode, const String& name, CodeType codeType, JSParserStrictness jsParserStrictness)
-        : m_sourceString(sourceCode.toString())
+        : m_sourceCode(sourceCode)
         , m_name(name)
         , m_flags((codeType << 1) | jsParserStrictness)
+        , m_hash(string().impl()->hash())
     {
     }
 
     SourceCodeKey(WTF::HashTableDeletedValueType)
-        : m_sourceString(WTF::HashTableDeletedValue)
+        : m_name(WTF::HashTableDeletedValue)
     {
     }
 
-    bool isHashTableDeletedValue() const { return m_sourceString.isHashTableDeletedValue(); }
+    bool isHashTableDeletedValue() const { return m_name.isHashTableDeletedValue(); }
 
-    unsigned hash() const { return m_sourceString.impl()->hash(); }
+    unsigned hash() const { return m_hash; }
 
-    size_t length() const { return m_sourceString.length(); }
+    size_t length() const { return m_sourceCode.length(); }
 
-    bool isNull() const { return m_sourceString.isNull(); }
+    bool isNull() const { return m_sourceCode.isNull(); }
 
+    // To save memory, we compute our string on demand. It's expected that source
+    // providers cache their strings to make this efficient.
+    String string() const { return m_sourceCode.toString(); }
+
     bool operator==(const SourceCodeKey& other) const
     {
-        return m_flags == other.m_flags
+        return m_hash == other.m_hash
+            && length() == other.length()
+            && m_flags == other.m_flags
             && m_name == other.m_name
-            && m_sourceString == other.m_sourceString;
+            && string() == other.string();
     }
 
 private:
-    String m_sourceString;
+    SourceCode m_sourceCode;
     String m_name;
     unsigned m_flags;
+    unsigned m_hash;
 };
 
 struct SourceCodeKeyHash {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to