Patchwork [2,of,2] dirstate: optimize walk() by using match.visitdir()

login
register
mail settings
Submitter via Mercurial-devel
Date May 5, 2017, 4:39 p.m.
Message ID <6a41fb02f68f107d0045.1494002389@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/20458/
State Accepted
Headers show

Comments

via Mercurial-devel - May 5, 2017, 4:39 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1493999386 25200
#      Fri May 05 08:49:46 2017 -0700
# Node ID 6a41fb02f68f107d00457ff7da3b9956c7b4674e
# Parent  d89bf290dc63661e5e1cdc48753322c30560c15d
dirstate: optimize walk() by using match.visitdir()

We already have the logic for restricting directory walks in
match.visitdir() that we use for treemanifests. We should take
advantage of it when walking the working copy as well.

This speeds up "hg st -I rootfilesin:." on the Firefox repo from
0.587s to 0.305s on warm disk (and much more on cold disk). More time
is spent reading the dirstate than walking the working copy after.

I tried to find scenarios where calling match.visitdir() would be a
noticeable overhead, but I couldn't find any. I encourage the reader
to try for themselves, since this is performance-critical code.

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -1021,6 +1021,8 @@ 
             wadd = work.append
             while work:
                 nd = work.pop()
+                if not match.visitdir(nd):
+                    continue
                 skip = None
                 if nd == '.':
                     nd = ''