Changeset 143348 in webkit


Ignore:
Timestamp:
Feb 19, 2013 9:48:15 AM (11 years ago)
Author:
ggaren@apple.com
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.

Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r143346 r143348  
     12013-02-18  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Save space on keys in the CodeCache
     4        https://bugs.webkit.org/show_bug.cgi?id=110179
     5
     6        Reviewed by Oliver Hunt.
     7
     8        Share the SourceProvider's string instead of making our own copy. This
     9        chops off 16MB - 32MB from the CodeCache's memory footprint when full.
     10        (It's 16MB when the strings are LChar, and 32MB when they're UChar.)
     11
     12        * runtime/CodeCache.cpp:
     13        (JSC::CodeCache::getFunctionExecutableFromGlobalCode):
     14        * runtime/CodeCache.h: Removed a defunct enum value.
     15
     16        (JSC::SourceCodeKey::SourceCodeKey):
     17        (JSC::SourceCodeKey::isHashTableDeletedValue):
     18        (SourceCodeKey):
     19        (JSC::SourceCodeKey::hash):
     20        (JSC::SourceCodeKey::length):
     21        (JSC::SourceCodeKey::isNull):
     22        (JSC::SourceCodeKey::string):
     23        (JSC::SourceCodeKey::operator==): Store a SourceCode instead of a String
     24        so we can share our string with our SourceProvider. Cache our hash so
     25        we don't have to re-decode our string just to re-hash the table.
     26
    1272013-02-19  Zoltan Herczeg  <zherczeg@webkit.org>
    228
  • trunk/Source/JavaScriptCore/runtime/CodeCache.cpp

    r143133 r143348  
    106106UnlinkedFunctionExecutable* CodeCache::getFunctionExecutableFromGlobalCode(JSGlobalData& globalData, const Identifier& name, const SourceCode& source, ParserError& error)
    107107{
    108     SourceCodeKey key = SourceCodeKey(source, name.string(), SourceCodeKey::FunctionCallType, JSParseNormal);
     108    SourceCodeKey key = SourceCodeKey(source, name.string(), SourceCodeKey::FunctionType, JSParseNormal);
    109109    const Strong<JSCell>* result = m_sourceCode.find(key);
    110110    if (result)
  • trunk/Source/JavaScriptCore/runtime/CodeCache.h

    r143141 r143348  
    5656class SourceCodeKey {
    5757public:
    58     enum CodeType { EvalType, ProgramType, FunctionCallType, FunctionConstructType };
     58    enum CodeType { EvalType, ProgramType, FunctionType };
    5959
    6060    SourceCodeKey()
    61         : m_flags(0)
    6261    {
    6362    }
    6463
    6564    SourceCodeKey(const SourceCode& sourceCode, const String& name, CodeType codeType, JSParserStrictness jsParserStrictness)
    66         : m_sourceString(sourceCode.toString())
     65        : m_sourceCode(sourceCode)
    6766        , m_name(name)
    6867        , m_flags((codeType << 1) | jsParserStrictness)
     68        , m_hash(string().impl()->hash())
    6969    {
    7070    }
    7171
    7272    SourceCodeKey(WTF::HashTableDeletedValueType)
    73         : m_sourceString(WTF::HashTableDeletedValue)
     73        : m_name(WTF::HashTableDeletedValue)
    7474    {
    7575    }
    7676
    77     bool isHashTableDeletedValue() const { return m_sourceString.isHashTableDeletedValue(); }
     77    bool isHashTableDeletedValue() const { return m_name.isHashTableDeletedValue(); }
    7878
    79     unsigned hash() const { return m_sourceString.impl()->hash(); }
     79    unsigned hash() const { return m_hash; }
    8080
    81     size_t length() const { return m_sourceString.length(); }
     81    size_t length() const { return m_sourceCode.length(); }
    8282
    83     bool isNull() const { return m_sourceString.isNull(); }
     83    bool isNull() const { return m_sourceCode.isNull(); }
     84
     85    // To save memory, we compute our string on demand. It's expected that source
     86    // providers cache their strings to make this efficient.
     87    String string() const { return m_sourceCode.toString(); }
    8488
    8589    bool operator==(const SourceCodeKey& other) const
    8690    {
    87         return m_flags == other.m_flags
     91        return m_hash == other.m_hash
     92            && length() == other.length()
     93            && m_flags == other.m_flags
    8894            && m_name == other.m_name
    89             && m_sourceString == other.m_sourceString;
     95            && string() == other.string();
    9096    }
    9197
    9298private:
    93     String m_sourceString;
     99    SourceCode m_sourceCode;
    94100    String m_name;
    95101    unsigned m_flags;
     102    unsigned m_hash;
    96103};
    97104
Note: See TracChangeset for help on using the changeset viewer.