dirstate.walk: don't keep track of normalized files in parallel
authorSiddharth Agarwal <sid0@fb.com>
Tue, 31 Mar 2015 19:29:39 -0700
changeset 24560 b38bcf18993c
parent 24559 4728d6f7c69f
child 24561 6514030dc686
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.
mercurial/dirstate.py
--- a/mercurial/dirstate.py	Tue Mar 31 19:18:27 2015 -0700
+++ b/mercurial/dirstate.py	Tue Mar 31 19:29:39 2015 -0700
@@ -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]