[MERGE] Factor out the Graph.heads() cache from _RevisionTextVersionCache for reuse, and use it in commit.

Robert Collins robertc at robertcollins.net
Thu Oct 18 03:40:06 BST 2007


On Wed, 2007-10-17 at 21:33 -0500, John Arbash Meinel wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Robert Collins wrote:
> > This patch just makes the heads cache from the recent reconcile work
> > reusable, and reuses it in commit.
> > 
> > It doesn't solve the commit merge performance-  that requires changes to
> > heads() itself, but this seems sensible to me, as even very large trees
> > are still moderate in size in terms of potential head lookup:result
> > sizes.
> > 
> > E.g. mozilla is 55k items, with a set of 2 items as keys in the cache
> > and worst case a set of the same two items in the cache in the output,
> > for 2 sets of 2 (shared references) strings * 55K.
> > 
> > -Rob
> > 
> 
> +    def heads(self, keys):
> +        """Return the heads of keys.
> +
> +        :see also: Graph.heads.
> +        :param keys: The keys to calculate heads for.
> +        :return: A set containing the heads, which may be mutated without
> +            affecting future lookups.
> +        """
> +        keys = set(keys)
> +        try:
> +            return set(self._heads[keys])
> +        except KeyError:
> +            heads = self.graph.heads(keys)
> +            self._heads[keys] = heads
> +            return set(heads)
> 
> ^- It seems a little odd to always store the output of heads, but then wrap it
> in a set() either way. Why not do
> 
> keys = set(keys)
> try:
>   return self._heads[keys]
> except KeyError:
>   heads = self.graph.heads(keys)
>   heads = set(heads)
>   self._heads[keys] = heads
>   return heads
> 
> If you are worried about callers modifying your sets accidentally, you could use
> 
> heads = frozenset(heads)
> 
> otherwise:
> BB:tweak

Some code modifies the return value deliberately.

-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/20071018/6c2f4a42/attachment.pgp 


More information about the bazaar mailing list