[PATCH V2] graphmod: compute slow revset query once prior to reachableroots (issue4782)

Yuya Nishihara yuya at tcha.org
Tue Sep 8 15:22:18 UTC 2015


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1441720844 -32400
#      Tue Sep 08 23:00:44 2015 +0900
# Node ID 5c20f2034fffbafd406c0e4b1e7bbef9b3973965
# Parent  2f77cf0385ace2539f313da8132e05d03841d846
graphmod: compute slow revset query once prior to reachableroots (issue4782)

Because revsets query is evaluated lazily, "list(revs)" may take long for
complicated query. So we shouldn't iterate revs many times. This patch is the
easiest workaround for the issue4782. We could introduce more aggressive
caching, but it wouldn't be as fast as the simple baseset operation.

Gregory Szorc said "this makes `hg wip` on my Firefox clone ~4x faster than
3.5.1 (~6.5s to ~1.5s). This is after a regression in @ to ~45s."

diff --git a/mercurial/graphmod.py b/mercurial/graphmod.py
--- a/mercurial/graphmod.py
+++ b/mercurial/graphmod.py
@@ -260,6 +260,10 @@ def dagwalker(repo, revs):
         for mpar in mpars:
             gp = gpcache.get(mpar)
             if gp is None:
+                # precompute slow query as we know reachableroots() goes
+                # through all revs (issue4782)
+                if not isinstance(revs, revset.baseset):
+                    revs = revset.baseset(revs)
                 gp = gpcache[mpar] = revset.reachableroots(repo, revs, [mpar])
             if not gp:
                 parents.append(mpar)


More information about the Mercurial-devel mailing list