[PATCH 2 of 2] dirstate: only call lstat once per flags invocation

Bryan O'Sullivan bos at serpentine.com
Wed Apr 3 10:57:04 CDT 2013


# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1365004580 25200
#      Wed Apr 03 08:56:20 2013 -0700
# Node ID 812cdd7003123080483a433b4690c6aa75122c83
# Parent  5cbbc8b9ab28356138eead0c0539ba9e7afd1089
dirstate: only call lstat once per flags invocation

This makes a big difference to performance in some cases.

hg --time locate 'set:symlink()'

mozilla-central (70,000 files):

  before: 2.92 sec
  after:  2.47

another repo (170,000 files):

  before: 7.87 sec
  after:  6.86

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -130,11 +130,14 @@ class dirstate(object):
     def flagfunc(self, buildfallback):
         if self._checklink and self._checkexec:
             def f(x):
-                p = self._join(x)
-                if os.path.islink(p):
-                    return 'l'
-                if util.isexec(p):
-                    return 'x'
+                try:
+                    st = os.lstat(self._join(x))
+                    if util.statislink(st):
+                        return 'l'
+                    if util.statisexec(st):
+                        return 'x'
+                except OSError:
+                    pass
                 return ''
             return f
 


More information about the Mercurial-devel mailing list