~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: John Arbash Meinel
  • Date: 2010-08-05 16:27:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5374.
  • Revision ID: john@arbash-meinel.com-20100805162735-172opvx34sr5gpbl
Find a case where we are wasting a bit of memory.

Specifically the 'build_details' tuple contains a lot of wasted references,
and we hold on to one of these for each record we are fetching.
And for something like 'bzr pack', that is all keys.

For just loading all text build details on my bzr+ repository, With:
locations = b.repository.texts._index.get_build_details(b.repository.texts.keys())
This drops the memory consumption from:
WorkingSize   77604KiB
 to
WorkingSize   64640KiB

Or around 10.6MB. I worked it out to a savings of about 80 bytes/record
on data that can have hundreds of thousands of records (in 32-bit).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1182
1182
            if trans_id not in self._new_contents:
1183
1183
                continue
1184
1184
            new_path = self._limbo_name(trans_id)
1185
 
            os.rename(old_path, new_path)
 
1185
            osutils.rename(old_path, new_path)
1186
1186
            for descendant in self._limbo_descendants(trans_id):
1187
1187
                desc_path = self._limbo_files[descendant]
1188
1188
                desc_path = new_path + desc_path[len(old_path):]
2919
2919
    def rename(self, from_, to):
2920
2920
        """Rename a file from one path to another."""
2921
2921
        try:
2922
 
            os.rename(from_, to)
2923
 
        except OSError, e:
 
2922
            osutils.rename(from_, to)
 
2923
        except (IOError, OSError), e:
2924
2924
            if e.errno in (errno.EEXIST, errno.ENOTEMPTY):
2925
2925
                raise errors.FileExists(to, str(e))
2926
2926
            # normal OSError doesn't include filenames so it's hard to see where
2942
2942
        """Reverse all renames that have been performed"""
2943
2943
        for from_, to in reversed(self.past_renames):
2944
2944
            try:
2945
 
                os.rename(to, from_)
2946
 
            except OSError, e:
 
2945
                osutils.rename(to, from_)
 
2946
            except (OSError, IOError), e:
2947
2947
                raise errors.TransformRenameFailed(to, from_, str(e), e.errno)                
2948
2948
        # after rollback, don't reuse _FileMover
2949
2949
        past_renames = None