[rfc] [patch] trivial patch to speed up bzr log

Robert Collins robertc at robertcollins.net
Mon Jan 16 00:01:57 GMT 2006


On Mon, 2006-01-16 at 00:25 +0100, Denys Duchier wrote:
> Robert Collins <robertc at robertcollins.net> writes:
> 
> > I'm concerned that this will double the memory footprint of bzr in large
> > trees. (with -v on launchpad for instance, I'd be anticipating an 800Mb
> > memory footprint with this change.)
> 
> Robert explained on IRC that during pull, many weaves are simultaneously live
> and would all hold a cached copy of the last extracted revision.
> 
> > Caching an inventory as happens later in the thread is less of an issue
> > for me - there is only one per branch :).
> 
> I understand, and for the case of "bzr log" that is indeed sufficient.  However,
> wouldn't it be useful to have a generally safe way of caching stuff?  I believe
> I have thought of such a scheme, provided that you are willing to let major
> collections take care of clearing cached values.
> 
> The trick is to use an object with a self reference, that also holds the cached
> value as an attribute.  Something like this:
> 
> import weakref
> 
> class Cached(object):
>     def __init__(self, value):
>         self.value = value
>         self.self = self
> 
> we can then safely cache a value v as follows:
> 
> w = weakref.ref(Cached(v))
> 
> As long as no major collection occurs, w() returns the Cached object from which
> we can retrieve the cached value v.  After a major collection, w() returns None.
> 
> What to you think?

That could do it, but weakrefs in python are often stronger than
desired.

If this is needed for just a few areas, why not have a caching
decorator?

weave = CachingWeave(someweave)

and have CachingWeave.get* check a cache for entries before asking
someweave for them.

I'm not sure where this is needed for log, but if the call path
precludes this, you could replace the Caching weave in the object map
instead of the original weave, which should then fix that.

Rob

-- 
GPG key available at: <http://www.robertcollins.net/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060116/908164e2/attachment.pgp 


More information about the bazaar mailing list