Rev 3717: Changing back to using a single dict saves memory, in http://bzr.arbash-meinel.com/branches/bzr/1.8-dev/lighter_log_file

John Arbash Meinel john at arbash-meinel.com
Thu Sep 18 20:04:07 BST 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.8-dev/lighter_log_file

------------------------------------------------------------
revno: 3717
revision-id: john at arbash-meinel.com-20080918190406-r75lzwnmjjth94h6
parent: john at arbash-meinel.com-20080918182621-g2w4klj590g2zptb
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: lighter_log_file
timestamp: Thu 2008-09-18 14:04:06 -0500
message:
  Changing back to using a single dict saves memory,
  at the cost of CPU.
-------------- next part --------------
=== modified file 'bzrlib/log.py'
--- a/bzrlib/log.py	2008-09-18 18:26:21 +0000
+++ b/bzrlib/log.py	2008-09-18 19:04:06 +0000
@@ -583,63 +583,54 @@
     # ancestry_values contains a pointer from a revision_id to either a tuple,
     # or a frozenset() of a given per-file ancestry.
     ancestry_values = {_mod_revision.NULL_REVISION: frozenset()}
-    # ancestry_pointers maps from a whole-tree revision_id into the
-    # ancestry_values dictionary for the given revision. (So given a whole-tree
-    # revision_id, what is the per-file ancestry for that revision.)
-    ancestry_pointers = {}
-    _hits = [0, 0, 0, 0, 0, 0, 0]
+    _hits = [0, 0, 0, 0, 0, 0, 0, 0]
     for rev in sorted_rev_list:
         parents = parent_map[rev]
-        rev_pointer = None
         rev_ancestry = None
         if rev in modified_text_revisions:
             # We know this will be a new node
             rev_ancestry = [rev]
-            rev_pointer = rev
         for parent in parents:
-            if parent not in ancestry_pointers:
+            if parent not in ancestry_values:
                 # parent is a Ghost, which won't be present in
                 # sorted_rev_list, but we may access it later, so create an
                 # empty node for it
-                ancestry_pointers[parent] = _mod_revision.NULL_REVISION
-            if rev_pointer is None:
+                ancestry_values[parent] = frozenset()
+            if rev_ancestry is None:
                 # We don't have anything worked out yet, so just copy this
                 # parent's ancestry_pointer
-                rev_pointer = ancestry_pointers[parent]
+                rev_ancestry = ancestry_values[parent]
             else:
                 # Check to see if this other parent introduces any new
                 # revisions. If it doesn't then we don't need to create a new
                 # set.
-                parent_pointer = ancestry_pointers[parent]
-                if parent_pointer == rev_pointer:
+                parent_ancestry = ancestry_values[parent]
+                if rev_ancestry is None:
+                    rev_ancestry = ancestry_values[rev_pointer]
+                if parent_ancestry is rev_ancestry:
                     # They both point to the same ancestry value, so we know
                     # there is nothing new
                     _hits[5] += 1
                     continue
-                if rev_ancestry is None:
-                    rev_ancestry = ancestry_values[rev_pointer]
-                parent_ancestry = frozenset(ancestry_values[parent_pointer])
-                # We had to compute the frozenset, so just cache it
-                ancestry_values[parent_pointer] = parent_ancestry
+                parent_ancestry = frozenset(parent_ancestry)
                 new_revisions = parent_ancestry.difference(rev_ancestry)
                 if new_revisions:
                     # We need something that we can modify. We can use a simple
                     # list, because we are only adding the 'new_revisions', so
                     # we know that we won't have duplicates.
                     if not isinstance(rev_ancestry, list):
-                        _hits[6] += 1
                         rev_ancestry = list(rev_ancestry)
                     rev_ancestry.extend(new_revisions)
-                    # We will be creating a new value
-                    rev_pointer = rev
-        if rev_pointer is None:
-            rev_pointer = _mod_revision.NULL_REVISION
-        elif rev_pointer == rev:
-            # We are creating a new node update the value cache.
-            assert rev_ancestry is not None
-            ancestry_values[rev] = tuple(rev_ancestry)
-        assert rev_pointer in ancestry_values
-        ancestry_pointers[rev] = rev_pointer
+                    _hits[6] += 1
+                else:
+                    _hits[7] += 1
+        if rev_ancestry is None:
+            rev_ancestry = frozenset()
+        elif isinstance(rev_ancestry, list):
+            # We can use "tuple()" here to save memory at the cost of CPU, or
+            # use frozenset() which saves CPU but consumes RAM.
+            rev_ancestry = frozenset(rev_ancestry)
+        ancestry_values[rev] = rev_ancestry
 
     trev_ancestry = time.time()
 
@@ -649,26 +640,22 @@
         if len(parents) > 1:
             _hits[1] += 1
             leftparent = parents[0]
-            left_pointer = ancestry_pointers[leftparent]
-            left_ancestry = None
+            left_ancestry = ancestry_values[leftparent]
             for rightparent in parents[1:]:
-                right_pointer = ancestry_pointers[rightparent]
-                if right_pointer != left_pointer:
-                    _hits[3] += 1
-                    if left_ancestry is None:
-                        left_ancestry = ancestry_values[left_pointer]
-                        left_ancestry = frozenset(left_ancestry)
-                    right_ancestry = ancestry_values[right_pointer]
-                    if not left_ancestry.issuperset(right_ancestry):
-                        _hits[4] += 1
-                        return True
-                else:
+                right_ancestry = ancestry_values[rightparent]
+                if left_ancestry is right_ancestry:
                     _hits[2] += 1
+                    continue
+                _hits[3] += 1
+                left_ancestry = frozenset(left_ancestry)
+                if not left_ancestry.issuperset(right_ancestry):
+                    _hits[4] += 1
+                    return True
         return False
 
     trace.note('Found %s nodes, and %s unique values for %s view_revs'
                ' modified_text_revisions: %s',
-               len(ancestry_pointers), len(ancestry_values),
+               0, len(ancestry_values),
                len(view_revs_iter), len(modified_text_revisions))
 
     # filter from the view the revisions that did not change or merge 



More information about the bazaar-commits mailing list