branchcache: improve speed relative to the amount of heads
Updating the branch cache is quadratic to the amount of heads in the
repository. One consequence of this was that cloning a pathological
repository with 10,000 heads (and nothing else) took hours of CPU
time.
This patch makes one of the inner loop much faster, by removing a
changectx instantiation, and removes another entirely in cases where
there are no candidate branch heads which descend from other branch
heads.
--- a/mercurial/localrepo.py Sat Apr 30 12:55:07 2011 +0200
+++ b/mercurial/localrepo.py Sat Apr 30 12:56:28 2011 +0200
@@ -509,15 +509,17 @@
bheads.extend(newnodes)
if len(bheads) <= 1:
continue
+ bheads = sorted(bheads, key=lambda x: self[x].rev())
# starting from tip means fewer passes over reachable
while newnodes:
latest = newnodes.pop()
if latest not in bheads:
continue
- minbhrev = self[min([self[bh].rev() for bh in bheads])].node()
+ minbhrev = self[bheads[0]].node()
reachable = self.changelog.reachable(latest, minbhrev)
reachable.remove(latest)
- bheads = [b for b in bheads if b not in reachable]
+ if reachable:
+ bheads = [b for b in bheads if b not in reachable]
partial[branch] = bheads
def lookup(self, key):