Commit de5cc65c authored by ggaren@apple.com's avatar ggaren@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.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@143348 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent baca90d6
2013-02-18 Geoffrey Garen <ggaren@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 <zherczeg@webkit.org>
revertBranchPtrWithPatch is incorrect on ARM traditional
......
......@@ -105,7 +105,7 @@ UnlinkedEvalCodeBlock* CodeCache::getEvalCodeBlock(JSGlobalData& globalData, Eva
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());
......
......@@ -55,44 +55,51 @@ class SourceProvider;
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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment