[MERGE] Factor out the Graph.heads() cache from _RevisionTextVersionCache for reuse, and use it in commit.
John Arbash Meinel
john at arbash-meinel.com
Thu Oct 18 03:33:28 BST 2007
-----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
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFHFsX3JdeBCYSNAAMRAhfMAKCNFEOVwl3Se7UuZa0qjkyAl/XlSQCfY6fU
wgdxbl2Ir9+15ilQuKDM6HY=
=01gK
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list