# HG changeset patch # User Dan Villiom Podlaski Christiansen # Date 2011-04-30 10:56:28 # Node ID bcfe78c3d15c928cd0ab80625c640c81a0ae7d62 # Parent 421d56a055fd0f630a61b3ca502a0d16c9476f8d 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. diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -509,15 +509,17 @@ class localrepository(repo.repository): 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):