HeapProfiler: replace pointer based matching algorithm with string matching algorithm for strings_ member.

pros: decreased snapshot size.
cons: increased serialization time.

I've tested the implementation on gmail 90mb heap.
I saw no speed degradation on the serialization step.
The snapshot size lost ~3% of its size. 100Mb -> 97Mb.

BUG=none
R=alph@chromium.org, yangguo@chromium.org

Review URL: https://codereview.chromium.org/24120006

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16725 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
loislo@chromium.org 2013-09-16 09:16:03 +00:00
parent 043abcd38a
commit 2abe14b8f6
2 changed files with 10 additions and 8 deletions

View File

@ -2472,7 +2472,7 @@ void HeapSnapshotJSONSerializer::SerializeImpl() {
int HeapSnapshotJSONSerializer::GetStringId(const char* s) {
HashMap::Entry* cache_entry = strings_.Lookup(
const_cast<char*>(s), ObjectHash(s), true);
const_cast<char*>(s), StringHash(s), true);
if (cache_entry->value == NULL) {
cache_entry->value = reinterpret_cast<void*>(next_string_id_++);
}

View File

@ -628,7 +628,7 @@ class HeapSnapshotJSONSerializer {
public:
explicit HeapSnapshotJSONSerializer(HeapSnapshot* snapshot)
: snapshot_(snapshot),
strings_(ObjectsMatch),
strings_(StringsMatch),
next_node_id_(1),
next_string_id_(1),
writer_(NULL) {
@ -636,14 +636,16 @@ class HeapSnapshotJSONSerializer {
void Serialize(v8::OutputStream* stream);
private:
INLINE(static bool ObjectsMatch(void* key1, void* key2)) {
return key1 == key2;
INLINE(static bool StringsMatch(void* key1, void* key2)) {
return strcmp(reinterpret_cast<char*>(key1),
reinterpret_cast<char*>(key2)) == 0;
}
INLINE(static uint32_t ObjectHash(const void* key)) {
return ComputeIntegerHash(
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(key)),
v8::internal::kZeroHashSeed);
INLINE(static uint32_t StringHash(const void* string)) {
const char* s = reinterpret_cast<const char*>(string);
int len = static_cast<int>(strlen(s));
return StringHasher::HashSequentialString(
s, len, v8::internal::kZeroHashSeed);
}
int GetStringId(const char* s);