~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Andrew Bennetts
  • Date: 2009-08-05 02:05:43 UTC
  • mto: This revision was merged to the branch mainline in revision 4608.
  • Revision ID: andrew.bennetts@canonical.com-20090805020543-jic9o4s4hb30of7e
Create an LRUCache of basis inventories in _extract_and_insert_inventory_deltas.  Speeds up a 1.9->2a fetch of ~7000 bzr.dev revisions by >10%.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3978
3978
            else:
3979
3979
                new_pack.set_write_cache_size(1024*1024)
3980
3980
        for substream_type, substream in stream:
 
3981
            if 'stream' in debug.debug_flags:
 
3982
                mutter('inserting substream: %s', substream_type)
3981
3983
            if substream_type == 'texts':
3982
3984
                self.target_repo.texts.insert_record_stream(substream)
3983
3985
            elif substream_type == 'inventories':
4049
4051
    def _extract_and_insert_inventory_deltas(self, substream, serializer):
4050
4052
        target_rich_root = self.target_repo._format.rich_root_data
4051
4053
        target_tree_refs = self.target_repo._format.supports_tree_reference
 
4054
        inventory_cache = lru_cache.LRUCache(50)
4052
4055
        for record in substream:
4053
4056
            # Insert the delta directly
4054
4057
            inventory_delta_bytes = record.get_bytes_as('fulltext')
4068
4071
                            self.target_repo._format)
4069
4072
            revision_id = new_id
4070
4073
            parents = [key[0] for key in record.parents]
4071
 
            self.target_repo.add_inventory_by_delta(
4072
 
                basis_id, inv_delta, revision_id, parents)
 
4074
            basis_inv = inventory_cache.get(basis_id, None)
 
4075
            if basis_inv is not None:
 
4076
                # add_inventory_by_delta mutates the basis_inv!
 
4077
                basis_inv = basis_inv.copy()
 
4078
            validator, inv = self.target_repo.add_inventory_by_delta(
 
4079
                basis_id, inv_delta, revision_id, parents, basis_inv=basis_inv)
 
4080
            inventory_cache[revision_id] = inv
4073
4081
 
4074
4082
    def _extract_and_insert_inventories(self, substream, serializer,
4075
4083
            parse_delta=None):