Rev 2843: Merge index performance tweak. in http://people.ubuntu.com/~robertc/baz2.0/repository

Robert Collins robertc at robertcollins.net
Thu Oct 18 02:17:15 BST 2007


At http://people.ubuntu.com/~robertc/baz2.0/repository

------------------------------------------------------------
revno: 2843
revision-id: robertc at robertcollins.net-20071018011701-7wmqnr5t1lhv78pu
parent: robertc at robertcollins.net-20071018003057-67sqhzt0l5fh4jg7
parent: robertc at robertcollins.net-20071018011222-5o9z30dyowwxxrv9
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Thu 2007-10-18 11:17:01 +1000
message:
  Merge index performance tweak.
modified:
  bzrlib/index.py                index.py-20070712131115-lolkarso50vjr64s-1
    ------------------------------------------------------------
    revno: 2592.1.25.2.7.1.28.1.6.1.3.1.9.2.1.3.74.1.31.3.18.1.9.1.2.1.12.1.8.1.46.1.18.1.1.2.22
    revision-id: robertc at robertcollins.net-20071018011222-5o9z30dyowwxxrv9
    parent: pqm at pqm.ubuntu.com-20071016112750-1q8brfaq6metpfn8
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: index
    timestamp: Thu 2007-10-18 11:12:22 +1000
    message:
      (robertc) Improve index bisection lookup performance looking for keys in the parsed dict before doing bisection searches in the parsed ranges. (Robert Collins).
    modified:
      bzrlib/index.py                index.py-20070712131115-lolkarso50vjr64s-1
=== modified file 'bzrlib/index.py'
--- a/bzrlib/index.py	2007-10-17 20:48:21 +0000
+++ b/bzrlib/index.py	2007-10-18 01:17:01 +0000
@@ -585,14 +585,17 @@
         readv_ranges = []
         for location, key in location_keys:
             # can we answer from cache?
-            # - if we know the answer - yes
+            if self._bisect_nodes and key in self._bisect_nodes:
+                # We have the key parsed.
+                continue
             index = self._parsed_key_index(key)
             if (len(self._parsed_key_map) and 
                 self._parsed_key_map[index][0] <= key and
-                (self._parsed_key_map[index][1] > key or
+                (self._parsed_key_map[index][1] >= key or
                  # end of the file has been parsed
                  self._parsed_byte_map[index][1] == self._size)):
-                # the key has been parsed, so no lookup is needed
+                # the key has been parsed, so no lookup is needed even if its
+                # not present.
                 continue
             # - if we have examined this part of the file already - yes
             index = self._parsed_byte_index(location)
@@ -620,33 +623,35 @@
         pending_locations = set()
         for location, key in location_keys:
             # can we answer from cache?
-            index = self._parsed_key_index(key)
-            if (self._parsed_key_map[index][0] <= key and
-                (self._parsed_key_map[index][1] > key or
-                 # end of the file has been parsed
-                 self._parsed_byte_map[index][1] == self._size)):
+            if key in self._bisect_nodes:
                 # the key has been parsed, so no lookup is needed
-                if key in self._bisect_nodes:
-                    if self.node_ref_lists:
-                        # the references may not have been all parsed.
-                        value, refs = self._bisect_nodes[key]
-                        wanted_locations = []
-                        for ref_list in refs:
-                            for ref in ref_list:
-                                if ref not in self._keys_by_offset:
-                                    wanted_locations.append(ref)
-                        if wanted_locations:
-                            pending_locations.update(wanted_locations)
-                            pending_references.append((location, key))
-                            continue
-                        result.append(((location, key), (self, key,
-                            value, self._resolve_references(refs))))
-                    else:
-                        result.append(((location, key),
-                            (self, key, self._bisect_nodes[key])))
+                if self.node_ref_lists:
+                    # the references may not have been all parsed.
+                    value, refs = self._bisect_nodes[key]
+                    wanted_locations = []
+                    for ref_list in refs:
+                        for ref in ref_list:
+                            if ref not in self._keys_by_offset:
+                                wanted_locations.append(ref)
+                    if wanted_locations:
+                        pending_locations.update(wanted_locations)
+                        pending_references.append((location, key))
+                        continue
+                    result.append(((location, key), (self, key,
+                        value, self._resolve_references(refs))))
                 else:
+                    result.append(((location, key),
+                        (self, key, self._bisect_nodes[key])))
+                continue
+            else:
+                # has the region the key should be in, been parsed?
+                index = self._parsed_key_index(key)
+                if (self._parsed_key_map[index][0] <= key and
+                    (self._parsed_key_map[index][1] >= key or
+                     # end of the file has been parsed
+                     self._parsed_byte_map[index][1] == self._size)):
                     result.append(((location, key), False))
-                continue
+                    continue
             # no, is the key above or below the probed location:
             # get the range of the probed & parsed location
             index = self._parsed_byte_index(location)



More information about the bazaar-commits mailing list