# HG changeset patch # User Bryan O'Sullivan # Date 1361388698 28800 # Node ID 49ef9d0ca815216275bfb62af26dd84385c95388 # Parent 9955fc5ee24ba0916a63dbaef9458a7d9e0d110d 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. diff -r 9955fc5ee24b -r 49ef9d0ca815 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Wed Feb 20 11:31:34 2013 -0800 +++ b/mercurial/cmdutil.py Wed Feb 20 11:31:38 2013 -0800 @@ -1210,6 +1210,13 @@ 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 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)