Rev 3713: Trade off time versus memory consumption. 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 17:21:50 BST 2008


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

------------------------------------------------------------
revno: 3713
revision-id: john at arbash-meinel.com-20080918162150-vi5xcsfwrgaql0it
parent: john at arbash-meinel.com-20080918161558-745a1vuxechgcq8h
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: lighter_log_file
timestamp: Thu 2008-09-18 11:21:50 -0500
message:
  Trade off time versus memory consumption.
  
  [frozen]set() objects always waste a bit of memory, in order
  to avoid hash collisions. So if we cache the ancestry by
  using tuples instead of sets, we can save a bit of memory.
  For mysql, this is 272MB versus 380MB. However, it costs
  CPU time to regenerate all of these sets 56.7s versus 44.2s.
-------------- next part --------------
=== modified file 'bzrlib/log.py'
--- a/bzrlib/log.py	2008-09-18 16:15:58 +0000
+++ b/bzrlib/log.py	2008-09-18 16:21:50 +0000
@@ -584,7 +584,7 @@
                 # 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[parent] = frozenset()
+                ancestry[parent] = ()
             if rev_ancestry is None:
                 # We don't have anything worked out yet, so just copy this
                 # parent's ancestry
@@ -593,27 +593,28 @@
                 # 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_ancestry = ancestry[parent]
+                parent_ancestry = frozenset(ancestry[parent])
                 new_revisions = parent_ancestry.difference(rev_ancestry)
                 if new_revisions:
                     # We need to create a non-frozen set so that we can
                     # update it. If we already have a non-frozen set, then we
                     # are free to modify it.
-                    if isinstance(rev_ancestry, frozenset):
-                        rev_ancestry = set(rev_ancestry)
-                    rev_ancestry.update(new_revisions)
+                    if not isinstance(rev_ancestry, list):
+                        rev_ancestry = list(rev_ancestry)
+                    rev_ancestry.extend(new_revisions)
         if rev_ancestry is None:
-            ancestry[rev] = frozenset()
+            ancestry[rev] = ()
         else:
-            ancestry[rev] = frozenset(rev_ancestry)
+            ancestry[rev] = tuple(rev_ancestry)
 
     def is_merging_rev(r):
         parents = parent_map[r]
         if len(parents) > 1:
             leftparent = parents[0]
+            left_ancestry = frozenset(ancestry[leftparent])
             for rightparent in parents[1:]:
-                if not ancestry[leftparent].issuperset(
-                        ancestry[rightparent]):
+                right_ancestry = ancestry[rightparent]
+                if not left_ancestry.issuperset(right_ancestry):
                     return True
         return False
 



More information about the bazaar-commits mailing list