# HG changeset patch # User Pierre-Yves David # Date 2014-08-30 10:20:50 # Node ID 3c8fb24334e9efce745abecbfd08b511ea40b490 # Parent 731b2a90983b33e63fed859c9a0f7b09791e1bfb branchmap: issue a single call to `ancestors` for all heads There is no reason to make multiple calls. This provides a massive speedup for repo with a lot of heads. On a strongly headed repo this gives humble speedup in simple case: from 8.1097 to 5.1051 And massive speedup in other case: from 7.8787 to 0.1984 diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py --- a/mercurial/branchmap.py +++ b/mercurial/branchmap.py @@ -252,15 +252,11 @@ class branchcache(dict): newheadrevs.sort() bheadset.update(newheadrevs) - # This loop prunes out two kinds of heads - heads that are - # superseded by a head in newheadrevs, and newheadrevs that are not - # heads because an existing head is their descendant. - while newheadrevs: - latest = newheadrevs.pop() - if latest not in bheadset: - continue - ancestors = set(cl.ancestors([latest], min(bheadset))) - bheadset -= ancestors + # This prunes out two kinds of heads - heads that are superseded by + # a head in newheadrevs, and newheadrevs that are not heads because + # an existing head is their descendant. + ancestors = set(cl.ancestors(newheadrevs, min(bheadset))) + bheadset -= ancestors bheadrevs = sorted(bheadset) self[branch] = [cl.node(rev) for rev in bheadrevs] tiprev = bheadrevs[-1]