[rfc] [patch] trivial patch to speed up bzr log
Denys Duchier
duchier at ps.uni-sb.de
Sun Jan 15 23:25:08 GMT 2006
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?
Cheers,
--Denys
More information about the bazaar
mailing list