From 2abe14b8f6187c0a378acb2ae606053db416b926 Mon Sep 17 00:00:00 2001 From: "loislo@chromium.org" Date: Mon, 16 Sep 2013 09:16:03 +0000 Subject: [PATCH] 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 --- src/heap-snapshot-generator.cc | 2 +- src/heap-snapshot-generator.h | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/heap-snapshot-generator.cc b/src/heap-snapshot-generator.cc index bd47eec..25b1526 100644 --- a/src/heap-snapshot-generator.cc +++ b/src/heap-snapshot-generator.cc @@ -2472,7 +2472,7 @@ void HeapSnapshotJSONSerializer::SerializeImpl() { int HeapSnapshotJSONSerializer::GetStringId(const char* s) { HashMap::Entry* cache_entry = strings_.Lookup( - const_cast(s), ObjectHash(s), true); + const_cast(s), StringHash(s), true); if (cache_entry->value == NULL) { cache_entry->value = reinterpret_cast(next_string_id_++); } diff --git a/src/heap-snapshot-generator.h b/src/heap-snapshot-generator.h index 7b0cf8f..11d094a 100644 --- a/src/heap-snapshot-generator.h +++ b/src/heap-snapshot-generator.h @@ -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(key1), + reinterpret_cast(key2)) == 0; } - INLINE(static uint32_t ObjectHash(const void* key)) { - return ComputeIntegerHash( - static_cast(reinterpret_cast(key)), - v8::internal::kZeroHashSeed); + INLINE(static uint32_t StringHash(const void* string)) { + const char* s = reinterpret_cast(string); + int len = static_cast(strlen(s)); + return StringHasher::HashSequentialString( + s, len, v8::internal::kZeroHashSeed); } int GetStringId(const char* s); -- 2.7.4