Change in vdsm[master]: fileSD: Inline private constant in the single call site

nsoffer at redhat.com nsoffer at redhat.com
Thu Sep 25 18:30:03 UTC 2014


Nir Soffer has posted comments on this change.

Change subject: fileSD: Inline private constant in the single call site
......................................................................


Patch Set 2:

(1 comment)

http://gerrit.ovirt.org/#/c/32724/2/vdsm/storage/fileSD.py
File vdsm/storage/fileSD.py:

Line 646: 
Line 647:     # For pattern='*' in mixed pool (block and file domains)
Line 648:     # glob will return sd.BLOCKSD_DIR and sd.GLUSTERSD_DIR among
Line 649:     # real mount points. Remove these directories from glob results.
Line 650:     ignore_dirs = ('/' + sd.BLOCKSD_DIR, '/' + sd.GLUSTERSD_DIR)
> Why rebuilding this every time? It's fixed.
It makes the code easier to work with and the cost is insignificant. In the next lines you are going to the file system. Anything we do here will be hidden by that.

I did this small test:

    # module values.py
    A = 'A'
    B = 'B'

    # module const.py
    import values
    import glob

    T = ('/' + values.A, '/' + values.B)

    def f():
        t = ('/' + values.A, '/' + values.B)
        v = [n for n in glob.iglob('*') if not n.endswith(t)]

    def g():
        v = [n for n in glob.iglob('*') if not n.endswith(T)]

    if __name__ == '__main__':
        for i in xrange(10000):
            func()

Timing creating the tuple for each call:

    $ python -m timeit -v -s 'import const' -n 10000 'const.f()'
    raw times: 1.24 1.22 1.23
    10000 loops, best of 3: 122 usec per loop

Timing reusing global variable:

    $ python -m timeit -v -s 'import const' -n 10000 'const.g()'
    raw times: 1.22 1.23 1.23
    10000 loops, best of 3: 122 usec per loop

Profiling this show that there is no visible difference between both functions.

 $ python -m cProfile -stime const.py f | head -n10
         5220253 function calls (5220250 primitive calls) in 1.999 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    10000    0.396    0.000    0.803    0.000 fnmatch.py:45(filter)
  1020000    0.347    0.000    0.347    0.000 {method 'match' of '_sre.SRE_Pattern' objects}
    10000    0.328    0.000    0.328    0.000 {posix.listdir}
    10000    0.308    0.000    1.986    0.000 const.py:7(f)
  1020000    0.152    0.000    0.152    0.000 {method 'endswith' of 'str' objects}

 $ python -m cProfile -stime const.py g | head -n10
         5220253 function calls (5220250 primitive calls) in 1.952 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    10000    0.380    0.000    0.756    0.000 fnmatch.py:45(filter)
    10000    0.324    0.000    0.324    0.000 {posix.listdir}
  1020000    0.317    0.000    0.317    0.000 {method 'match' of '_sre.SRE_Pattern' objects}
    10000    0.306    0.000    1.940    0.000 const.py:11(g)
  1020000    0.156    0.000    0.156    0.000 {method 'endswith' of 'str' objects}
Line 651: 
Line 652:     mntList = [mnt for mnt in glob.iglob(fileDomPattern)
Line 653:                if not mnt.endswith(ignore_dirs)]
Line 654: 


-- 
To view, visit http://gerrit.ovirt.org/32724
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: If8430a05dd454c34217bb051345633aec4351738
Gerrit-PatchSet: 2
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>
Gerrit-Reviewer: Allon Mureinik <amureini at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Federico Simoncelli <fsimonce at redhat.com>
Gerrit-Reviewer: Nir Soffer <nsoffer at redhat.com>
Gerrit-Reviewer: Yoav Kleinberger <ykleinbe at redhat.com>
Gerrit-Reviewer: automation at ovirt.org
Gerrit-Reviewer: oVirt Jenkins CI Server
Gerrit-HasComments: Yes


More information about the vdsm-patches mailing list