Patchwork [2,of,3] dirstate: test normalize is not None instead of using a no-op lambda

login
register
mail settings
Submitter Siddharth Agarwal
Date Dec. 3, 2012, 10:23 p.m.
Message ID <98f5d2b441abc677c2b2.1354573434@sid0x220>
Download mbox | patch
Permalink /patch/2/
State Superseded
Headers show

Comments

Siddharth Agarwal - Dec. 3, 2012, 10:23 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1354570962 28800
# Node ID 98f5d2b441abc677c2b2fbaa3900de2afc193247
# Parent  8909a6b5f3028378258675aa51a972b8bc0a77f0
dirstate: test normalize is not None instead of using a no-op lambda

hg perfstatus -u on a working directory with 170,000 files, without this
change:
! wall 1.869404 comb 1.850000 user 1.170000 sys 0.680000 (best of 6)

With this change:
! wall 1.839561 comb 1.830000 user 1.120000 sys 0.710000 (best of 6)
Matt Mackall - Dec. 3, 2012, 10:33 p.m.
On Mon, 2012-12-03 at 14:23 -0800, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0 at fb.com>
> # Date 1354570962 28800
> # Node ID 98f5d2b441abc677c2b2fbaa3900de2afc193247
> # Parent  8909a6b5f3028378258675aa51a972b8bc0a77f0
> dirstate: test normalize is not None instead of using a no-op lambda
> 
> hg perfstatus -u on a working directory with 170,000 files, without this
> change:
> ! wall 1.869404 comb 1.850000 user 1.170000 sys 0.680000 (best of 6)
> 
> With this change:
> ! wall 1.839561 comb 1.830000 user 1.120000 sys 0.710000 (best of 6)
> 
> +            if normalize is not None:
> +                nf = normalize(normpath(ff), False, True)

$ python -m timeit -s 'n = None' -c 'if n: pass'
100000000 loops, best of 3: 0.0143 usec per loop
$ python -m timeit -s 'n = None' -c 'if n is not None: pass'
100000000 loops, best of 3: 0.0178 usec per loop
Siddharth Agarwal - Dec. 4, 2012, 12:32 a.m.
On 12/03/2012 02:33 PM, Matt Mackall wrote:
> $ python -m timeit -s 'n = None' -c 'if n: pass'
> 100000000 loops, best of 3: 0.0143 usec per loop
> $ python -m timeit -s 'n = None' -c 'if n is not None: pass'
> 100000000 loops, best of 3: 0.0178 usec per loop

Switching to "if normalize:" didn't bring about a measurable difference 
to perfstatus -u. The lambda variant is relatively a lot slower, so 
there's no surprise that I saw a perf difference there. On my install:

$ python -m timeit -s 'n = lambda x, y, z: x' -c 'n(True, True, True)'
1000000 loops, best of 3: 0.22 usec per loop
$ python -m timeit -s 'n = lambda x, y, z: x' -c 'n(None, None, None)'
10000000 loops, best of 3: 0.142 usec per loop
$ python -m timeit -s 'n = None' -c 'if n is not None: pass'
10000000 loops, best of 3: 0.044 usec per loop
$ python -m timeit -s 'n = None' -c 'if n: pass'
10000000 loops, best of 3: 0.036 usec per loop

However, if you think it's better clarity-wise, I can resend the patch 
with the change.
Matt Mackall - Dec. 4, 2012, 7:29 a.m.
On Mon, 2012-12-03 at 16:32 -0800, Siddharth Agarwal wrote:
> On 12/03/2012 02:33 PM, Matt Mackall wrote:
> > $ python -m timeit -s 'n = None' -c 'if n: pass'
> > 100000000 loops, best of 3: 0.0143 usec per loop
> > $ python -m timeit -s 'n = None' -c 'if n is not None: pass'
> > 100000000 loops, best of 3: 0.0178 usec per loop
> 
> Switching to "if normalize:" didn't bring about a measurable difference 
> to perfstatus -u. The lambda variant is relatively a lot slower, so 
> there's no surprise that I saw a perf difference there. On my install:
> 
> $ python -m timeit -s 'n = lambda x, y, z: x' -c 'n(True, True, True)'
> 1000000 loops, best of 3: 0.22 usec per loop
> $ python -m timeit -s 'n = lambda x, y, z: x' -c 'n(None, None, None)'
> 10000000 loops, best of 3: 0.142 usec per loop
> $ python -m timeit -s 'n = None' -c 'if n is not None: pass'
> 10000000 loops, best of 3: 0.044 usec per loop
> $ python -m timeit -s 'n = None' -c 'if n: pass'
> 10000000 loops, best of 3: 0.036 usec per loop
> 
> However, if you think it's better clarity-wise, I can resend the patch 
> with the change.

Please.

Patch

diff -r 8909a6b5f302 -r 98f5d2b441ab mercurial/dirstate.py
--- a/mercurial/dirstate.py	Mon Dec 03 13:53:53 2012 -0800
+++ b/mercurial/dirstate.py	Mon Dec 03 13:42:42 2012 -0800
@@ -605,7 +605,7 @@ 
             normalize = self._normalize
             skipstep3 = False
         else:
-            normalize = lambda x, y, z: x
+            normalize = None
 
         files = sorted(match.files())
         subrepos.sort()
@@ -626,7 +626,10 @@ 
 
         # step 1: find all explicit files
         for ff in files:
-            nf = normalize(normpath(ff), False, True)
+            if normalize is not None:
+                nf = normalize(normpath(ff), False, True)
+            else:
+                nf = normpath(ff)
             if nf in results:
                 continue
 
@@ -676,7 +679,10 @@ 
                     continue
                 raise
             for f, kind, st in entries:
-                nf = normalize(nd and (nd + "/" + f) or f, True, True)
+                if normalize is not None:
+                    nf = normalize(nd and (nd + "/" + f) or f, True, True)
+                else:
+                    nf = nd and (nd + "/" + f) or f
                 if nf not in results:
                     if kind == dirkind:
                         if not ignore(nf):