Revision: 16725
Author:   loi...@chromium.org
Date:     Mon Sep 16 09:16:03 2013 UTC
Log: 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=a...@chromium.org, yang...@chromium.org

Review URL: https://codereview.chromium.org/24120006
http://code.google.com/p/v8/source/detail?r=16725

Modified:
 /branches/bleeding_edge/src/heap-snapshot-generator.cc
 /branches/bleeding_edge/src/heap-snapshot-generator.h

=======================================
--- /branches/bleeding_edge/src/heap-snapshot-generator.cc Wed Sep 11 07:14:41 2013 UTC +++ /branches/bleeding_edge/src/heap-snapshot-generator.cc Mon Sep 16 09:16:03 2013 UTC
@@ -2472,7 +2472,7 @@

 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_++);
   }
=======================================
--- /branches/bleeding_edge/src/heap-snapshot-generator.h Tue Sep 10 14:30:36 2013 UTC +++ /branches/bleeding_edge/src/heap-snapshot-generator.h Mon Sep 16 09:16:03 2013 UTC
@@ -628,7 +628,7 @@
  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 @@
   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);

--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to