[PATCH 2 of 3] dirstate.walk: don't keep track of normalized files in parallel

Siddharth Agarwal sid0 at fb.com
Tue Mar 31 22:24:42 CDT 2015


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1427855379 25200
#      Tue Mar 31 19:29:39 2015 -0700
# Node ID 08b7cf83a76bfa709fd94381b1fb1708ca42465f
# Parent  61968dd3c613020955a7cd335f979f3bf2995dcc
dirstate.walk: don't keep track of normalized files in parallel

Rev 2bb13f2b778c changed the semantics of the work list to store (normalized,
non-normalized) pairs. All the tuple creation and destruction hurts perf: on a
large repo on OS X, 'hg status' went from 3.62 seconds to 3.78.

It also is unnecessary in most cases:
- it is clearly unnecessary on case-sensitive filesystems.
- it is also unnecessary when filenames have been read off of disk rather than
  being supplied by the user.

The only case where the non-normalized case is required at all is when the file
is unknown.

To eliminate most of the perf cost, keep trace of whether the directory needs
to be normalized at all with a boolean called 'alreadynormed'. Pay the cost of
directory normalization only when necessary.

For the above large repo, 'hg status' goes to 3.63 seconds.

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -744,9 +744,11 @@
             skipstep3 = True
 
         if not exact and self._checkcase:
+            normalize = self._normalize
             normalizefile = self._normalizefile
             skipstep3 = False
         else:
+            normalize = self._normalize
             normalizefile = None
 
         # step 1: find all explicit files
@@ -756,14 +758,13 @@
         work = [d for d in work if not dirignore(d[0])]
 
         # step 2: visit subdirectories
-        def traverse(work):
+        def traverse(work, alreadynormed):
             wadd = work.append
             while work:
-                nd, d = work.pop()
+                nd = work.pop()
                 skip = None
                 if nd == '.':
                     nd = ''
-                    d = ''
                 else:
                     skip = '.hg'
                 try:
@@ -780,28 +781,34 @@
                         # dmap -- therefore normalizefile is enough
                         nf = normalizefile(nd and (nd + "/" + f) or f, True,
                                            True)
-                        f = d and (d + "/" + f) or f
                     else:
                         nf = nd and (nd + "/" + f) or f
-                        f = nf
                     if nf not in results:
                         if kind == dirkind:
                             if not ignore(nf):
                                 if matchtdir:
                                     matchtdir(nf)
-                                wadd((nf, f))
+                                wadd(nf)
                             if nf in dmap and (matchalways or matchfn(nf)):
                                 results[nf] = None
                         elif kind == regkind or kind == lnkkind:
                             if nf in dmap:
                                 if matchalways or matchfn(nf):
                                     results[nf] = st
-                            elif (matchalways or matchfn(f)) and not ignore(nf):
+                            elif ((matchalways or matchfn(nf))
+                                  and not ignore(nf)):
+                                # unknown file -- normalize if necessary
+                                if not alreadynormed:
+                                    nf = normalize(nf, False, True)
                                 results[nf] = st
                         elif nf in dmap and (matchalways or matchfn(nf)):
                             results[nf] = None
 
-        traverse(work)
+        for nd, d in work:
+            # alreadynormed means that processwork doesn't have to do any
+            # expensive directory normalization
+            alreadynormed = not normalize or nd == d
+            traverse([d], alreadynormed)
 
         for s in subrepos:
             del results[s]


More information about the Mercurial-devel mailing list