Rev 5525: Avoid the per-entry allocation of a Search object. in http://bazaar.launchpad.net/~jameinel/bzr/2.3-gcb-peak-mem

John Arbash Meinel john at arbash-meinel.com
Mon Nov 22 17:13:51 GMT 2010


At http://bazaar.launchpad.net/~jameinel/bzr/2.3-gcb-peak-mem

------------------------------------------------------------
revno: 5525
revision-id: john at arbash-meinel.com-20101122171321-s0m41he5mvzu6v5u
parent: john at arbash-meinel.com-20101122170734-uf14pq1951tx1t7s
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.3-gcb-peak-mem
timestamp: Mon 2010-11-22 11:13:21 -0600
message:
  Avoid the per-entry allocation of a Search object.
-------------- next part --------------
=== modified file 'bzrlib/_delta_index_pyx.pyx'
--- a/bzrlib/_delta_index_pyx.pyx	2010-11-22 17:07:34 +0000
+++ b/bzrlib/_delta_index_pyx.pyx	2010-11-22 17:13:21 +0000
@@ -300,20 +300,15 @@
         memset(new_table, 0, n_bytes)
         self._swap_table(new_table, table_size - 1)
 
-    cdef RabinEntrySearch search(self, unsigned int rabin_val):
-        """Initialize a search."""
-        cdef RabinEntrySearch search
-        search = RabinEntrySearch(self)
-        search.start(rabin_val)
-        return search
-
     cdef rabin_entry *add(self, const_data ptr, unsigned int global_offset,
                           unsigned int val, Py_ssize_t match_pre,
-                          Py_ssize_t match_tail) except NULL:
+                          Py_ssize_t match_tail,
+                          RabinEntrySearch search=None) except NULL:
         """Add this entry to the hash map."""
-        cdef RabinEntrySearch search
         cdef rabin_entry *entry
-        search = self.search(val)
+        if search is None:
+            search = RabinEntrySearch(self)
+        search.start(val)
         # Search until we find the first empty slot
         while search.free_slot == NULL:
             search.next()
@@ -371,7 +366,8 @@
                                 0, 0))
         else:
             rabin_val = val
-            search = self.search(rabin_val)
+            search = RabinEntrySearch(self)
+            search.start(rabin_val)
             search.next()
             while search.entry != NULL:
                 matches.append((search.entry.rabin_val,
@@ -513,6 +509,7 @@
         cdef Py_ssize_t size
         cdef rabin_entry *last
         cdef unsigned int hash_offset
+        cdef RabinEntrySearch search
 
         if not PyString_CheckExact(source):
             raise TypeError('source must be a str')
@@ -530,7 +527,8 @@
         #       alignment didn't seem to help anything. We only ended up with a
         #       1/4 chance of having both source and target aligned.
         ptr = start
-        last == NULL
+        last = NULL
+        search = RabinEntrySearch(self._hash_map)
         while ptr < end - RABIN_WINDOW:
             val = 0
             for i from 1 <= i <= RABIN_WINDOW:
@@ -545,7 +543,8 @@
                 pass
             else:
                 last = self._hash_map.add(ptr, global_offset,
-                                          val, match_pre, match_tail)
+                                          val, match_pre, match_tail,
+                                          search)
 
     def _compute_offsets_from_delta(self, delta_source, start_offset):
         cdef unsigned int global_offset



More information about the bazaar-commits mailing list