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

login
register
mail settings
Submitter Bryan O'Sullivan
Date April 3, 2013, 3:57 p.m.
Message ID <812cdd7003123080483a.1365004624@australite.local>
Download mbox | patch
Permalink /patch/1253/
State Accepted
Commit e8b4b139a5451bfc72b24a82f37e19a198f167ee
Headers show

Comments

Bryan O'Sullivan - April 3, 2013, 3:57 p.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano@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

Patch

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