Patchwork [1,of,2] cmdutil: use a small initial window with --limit

login
register
mail settings
Submitter Bryan O'Sullivan
Date Feb. 19, 2013, 11:47 p.m.
Message ID <77b02f572b752fcbec87.1361317626@australite.thefacebook.com>
Download mbox | patch
Permalink /patch/1036/
State Accepted
Commit 49ef9d0ca815216275bfb62af26dd84385c95388
Headers show

Comments

Bryan O'Sullivan - Feb. 19, 2013, 11:47 p.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano@fb.com>
# Date 1361317585 28800
# Node ID 77b02f572b752fcbec87f576564880ec1dc9023b
# Parent  aeca36ccd9a5c9dc5894fdd5456c3eb29a65b672
cmdutil: use a small initial window with --limit

In a large repo, running a command like "log -l1 -p" was expensive because
it would always traverse 8 commits, as 8 was the initial window size.

We now choose the lesser of 8 or the limit, speeding up the "log -l1 -p"
case by a factor of 5.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1210,6 +1210,13 @@  def walkchangerevs(repo, match, opts, pr
             if ff.match(x):
                 wanted.discard(x)
 
+    # Choose a small initial window if we will probably only visit a
+    # few commits.
+    limit = loglimit(opts)
+    windowsize = 8
+    if limit:
+        windowsize = min(limit, windowsize)
+
     # Now that wanted is correctly initialized, we can iterate over the
     # revision range, yielding only revisions in wanted.
     def iterate():
@@ -1221,7 +1228,7 @@  def walkchangerevs(repo, match, opts, pr
             def want(rev):
                 return rev in wanted
 
-        for i, window in increasingwindows(0, len(revs)):
+        for i, window in increasingwindows(0, len(revs), windowsize):
             nrevs = [rev for rev in revs[i:i + window] if want(rev)]
             for rev in sorted(nrevs):
                 fns = fncache.get(rev)