[MERGE/RFC] "bzr branch" opens the source branch twice, and the pack-names 12 times

John Arbash Meinel john at arbash-meinel.com
Sat Nov 29 00:53:29 GMT 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin Pool wrote:
> Just a question from while I was merging this (the precise lines are
> from my conflict resolution so they're not verbatim from your patch):
> 
>         elif self._file is None:
>             data_ranges = self._transport.readv(self._name, ranges)
>         else:
>             data_ranges = []
>             for offset, size in ranges:
>                 self._file.seek(offset)
>                 data_ranges.append((offset, self._file.read(size)))
> 
> Did you find that using a python file directly was substantially
> faster than using a transport object?  It would be nice to provide
> apis there that map through to something just as fast.
> 

When self._file is not None then we have used a NamedTemporaryFile, and
this specific BTreeIndex is a 'spill over' index.

On Windows, you can't read from the filename of a named temporary file,
only from the currently open file handle. I don't know what *use* the
name is, since it can't be opened by this process or any other process.
Anyway, it means we *have* to use the exact file handle that we opened,
because we just can't read from it any other way.

We use a (Named)TemporaryFile because we want the file to be
automatically deleted when it goes out of scope. We use the temp files
to avoid buffering everything in memory. (If we get more than 100k keys,
we spill to disk, and then read it back in later and merge sort it with
the other indexes to generate one large index.)

As for being faster or not... I didn't specifically test, but I would
assume that keeping a file handle open is faster than opening it,
reading, closing it, and then repeating for the next segment.
Transport.readv() as written does re-open the file for each request. But
the code you are asking about isn't that way for performance, just out
of necessity.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkkwkokACgkQJdeBCYSNAANjZwCgpck5OioqNg2waxr7S6H8SOF1
PaQAni6n7CeV/+/3JYO4/dQkz12mITyx
=jxqS
-----END PGP SIGNATURE-----



More information about the bazaar mailing list