~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/groupcompress.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-10-26 15:59:54 UTC
  • mfrom: (4679.9.25 2.1-static-tuple-chk-map)
  • Revision ID: pqm@pqm.ubuntu.com-20091026155954-r9gw2rizkikw7cg7
(jam) Start using StaticTuple as part of the chk_map code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1269
1269
        """See VersionedFiles.clear_cache()"""
1270
1270
        self._group_cache.clear()
1271
1271
        self._index._graph_index.clear_cache()
 
1272
        self._index._int_cache.clear()
1272
1273
 
1273
1274
    def _check_add(self, key, lines, random_id, check_content):
1274
1275
        """check that version_id and lines are safe to add."""
1832
1833
        self.has_graph = parents
1833
1834
        self._is_locked = is_locked
1834
1835
        self._inconsistency_fatal = inconsistency_fatal
 
1836
        # GroupCompress records tend to have the same 'group' start + offset
 
1837
        # repeated over and over, this creates a surplus of ints
 
1838
        self._int_cache = {}
1835
1839
        if track_external_parent_refs:
1836
1840
            self._key_dependencies = knit._KeyRefs(
1837
1841
                track_new_keys=track_new_keys)
2013
2017
        """Convert an index value to position details."""
2014
2018
        bits = node[2].split(' ')
2015
2019
        # It would be nice not to read the entire gzip.
 
2020
        # start and stop are put into _int_cache because they are very common.
 
2021
        # They define the 'group' that an entry is in, and many groups can have
 
2022
        # thousands of objects.
 
2023
        # Branching Launchpad, for example, saves ~600k integers, at 12 bytes
 
2024
        # each, or about 7MB. Note that it might be even more when you consider
 
2025
        # how PyInt is allocated in separate slabs. And you can't return a slab
 
2026
        # to the OS if even 1 int on it is in use. Note though that Python uses
 
2027
        # a LIFO when re-using PyInt slots, which probably causes more
 
2028
        # fragmentation.
2016
2029
        start = int(bits[0])
 
2030
        start = self._int_cache.setdefault(start, start)
2017
2031
        stop = int(bits[1])
 
2032
        stop = self._int_cache.setdefault(stop, stop)
2018
2033
        basis_end = int(bits[2])
2019
2034
        delta_end = int(bits[3])
2020
 
        return node[0], start, stop, basis_end, delta_end
 
2035
        # We can't use StaticTuple here, because node[0] is a BTreeGraphIndex
 
2036
        # instance...
 
2037
        return (node[0], start, stop, basis_end, delta_end)
2021
2038
 
2022
2039
    def scan_unvalidated_index(self, graph_index):
2023
2040
        """Inform this _GCGraphIndex that there is an unvalidated index.