cmdutil: stop pretending we can calculate revs for graphlog lazily
authorSiddharth Agarwal <sid0@fb.com>
Fri, 28 Dec 2012 16:25:00 -0800
changeset 18171 9d350f2d9458
parent 18170 0dcc77b271b9
child 18172 e6c5e0092469
cmdutil: stop pretending we can calculate revs for graphlog lazily cmdutil.getgraphlogrevs does a ton of work trying to build a graphlog lazily, and then cmdutil.graphlog comes along and destroys all of that. graphmod.dagwalker requires that it be given the full list of revs upfront so that it can perform filtering and tests against known revs. For a repository with over 400,000 changesets, this speeds up graphlog by around 0.02 seconds (~20% with a small limit).
mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Fri Dec 28 16:24:36 2012 -0800
+++ b/mercurial/cmdutil.py	Fri Dec 28 16:25:00 2012 -0800
@@ -1399,34 +1399,8 @@
     callable taking a revision number and returning a match objects
     filtering the files to be detailed when displaying the revision.
     """
-    def increasingrevs(repo, revs, matcher):
-        # The sorted input rev sequence is chopped in sub-sequences
-        # which are sorted in ascending order and passed to the
-        # matcher. The filtered revs are sorted again as they were in
-        # the original sub-sequence. This achieve several things:
-        #
-        # - getlogrevs() now returns a generator which behaviour is
-        #   adapted to log need. First results come fast, last ones
-        #   are batched for performances.
-        #
-        # - revset matchers often operate faster on revision in
-        #   changelog order, because most filters deal with the
-        #   changelog.
-        #
-        # - revset matchers can reorder revisions. "A or B" typically
-        #   returns returns the revision matching A then the revision
-        #   matching B. We want to hide this internal implementation
-        #   detail from the caller, and sorting the filtered revision
-        #   again achieves this.
-        for i, window in increasingwindows(0, len(revs), windowsize=1):
-            orevs = revs[i:i + window]
-            nrevs = set(matcher(repo, sorted(orevs)))
-            for rev in orevs:
-                if rev in nrevs:
-                    yield rev
-
     if not len(repo):
-        return iter([]), None, None
+        return [], None, None
     # Default --rev value depends on --follow but --follow behaviour
     # depends on revisions resolved from --rev...
     follow = opts.get('follow') or opts.get('follow_first')
@@ -1443,20 +1417,25 @@
             revs = list(repo.changelog)
             revs.reverse()
     if not revs:
-        return iter([]), None, None
+        return [], None, None
     expr, filematcher = _makegraphlogrevset(repo, pats, opts, revs)
     if possiblyunsorted:
         revs.sort(reverse=True)
     if expr:
+        # Revset matchers often operate faster on revisions in changelog
+        # order, because most filters deal with the changelog.
+        revs.reverse()
         matcher = revset.match(repo.ui, expr)
-        revs = increasingrevs(repo, revs, matcher)
+        # Revset matches can reorder revisions. "A or B" typically returns
+        # returns the revision matching A then the revision matching B. Sort
+        # again to fix that.
+        revs = matcher(repo, revs)
+        revs.sort(reverse=True)
     if not opts.get('hidden'):
         # --hidden is still experimental and not worth a dedicated revset
         # yet. Fortunately, filtering revision number is fast.
         hiddenrevs = repo.hiddenrevs
-        revs = (r for r in revs if r not in hiddenrevs)
-    else:
-        revs = iter(revs)
+        revs = [r for r in revs if r not in hiddenrevs]
     return revs, expr, filematcher
 
 def displaygraph(ui, dag, displayer, showparents, edgefn, getrenamed=None,
@@ -1491,7 +1470,6 @@
 def graphlog(ui, repo, *pats, **opts):
     # Parameters are identical to log command ones
     revs, expr, filematcher = getgraphlogrevs(repo, pats, opts)
-    revs = sorted(revs, reverse=1)
     limit = loglimit(opts)
     if limit is not None:
         revs = revs[:limit]