Rev 3813: Streamline Inventory._make_delta, especially when re-using cached entries. in http://bzr.arbash-meinel.com/branches/bzr/brisbane/xml_cache

John Arbash Meinel john at arbash-meinel.com
Thu Dec 11 00:06:28 GMT 2008


At http://bzr.arbash-meinel.com/branches/bzr/brisbane/xml_cache

------------------------------------------------------------
revno: 3813
revision-id: john at arbash-meinel.com-20081211000604-kzutwqr3jkeez10s
parent: john at arbash-meinel.com-20081210231131-1kib0b2lzj993iy5
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: xml_cache
timestamp: Wed 2008-12-10 18:06:04 -0600
message:
  Streamline Inventory._make_delta, especially when re-using cached entries.
  
  Also streamline some other items, like direct access to the byid dict.
  Avoid doing an intersection check if the difference checks show nothing new.
-------------- next part --------------
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py	2008-12-09 04:26:46 +0000
+++ b/bzrlib/inventory.py	2008-12-11 00:06:04 +0000
@@ -342,6 +342,8 @@
                    self.revision))
 
     def __eq__(self, other):
+        if other is self:
+            return True
         if not isinstance(other, InventoryEntry):
             return NotImplemented
 
@@ -1277,20 +1279,33 @@
 
     def _make_delta(self, old):
         """Make an inventory delta from two inventories."""
-        old_ids = set(old)
-        new_ids = set(self)
+        old_getter = getattr(old, '_byid', old)
+        new_getter = self._byid
+        old_ids = set(old_getter)
+        new_ids = set(new_getter)
         adds = new_ids - old_ids
         deletes = old_ids - new_ids
-        common = old_ids.intersection(new_ids)
+        if not adds and not deletes:
+            common = new_ids
+        else:
+            common = old_ids.intersection(new_ids)
         delta = []
         for file_id in deletes:
             delta.append((old.id2path(file_id), None, file_id, None))
         for file_id in adds:
             delta.append((None, self.id2path(file_id), file_id, self[file_id]))
         for file_id in common:
-            if old[file_id] != self[file_id]:
+            new_ie = new_getter[file_id]
+            old_ie = old_getter[file_id]
+            # If xml_serializer returns the cached InventoryEntries (rather
+            # than always doing .copy()), inlining the 'is' check saves 2.7M
+            # calls to __eq__.  Under lsprof this saves 20s => 6s.
+            # It is a minor improvement without lsprof.
+            if old_ie is new_ie or old_ie == new_ie:
+                continue
+            else:
                 delta.append((old.id2path(file_id), self.id2path(file_id),
-                    file_id, self[file_id]))
+                              file_id, new_ie))
         return delta
 
     def remove_recursive_id(self, file_id):

=== modified file 'bzrlib/xml8.py'
--- a/bzrlib/xml8.py	2008-12-10 23:11:31 +0000
+++ b/bzrlib/xml8.py	2008-12-11 00:06:04 +0000
@@ -427,10 +427,9 @@
             pass
         else:
             # Only copying directory entries drops us 2.85s => 2.35s
-            # if cached_ie.kind == 'directory':
-            #     return cached_ie.copy()
-            # return cached_ie
-            return cached_ie.copy()
+            if cached_ie.kind == 'directory':
+                return cached_ie.copy()
+            return cached_ie
 
         kind = elt.tag
         if not InventoryEntry.versionable_kind(kind):



More information about the bazaar-commits mailing list