tests/filterpyflakes.py
author Na'Tosha Bard <natosha@unity3d.com>
Mon, 13 Feb 2012 18:37:07 +0100
changeset 16120 47ee41fcf42b
parent 14209 08d84bdce1a5
child 19335 77440de177f7
permissions -rwxr-xr-x
largefiles: optimize update speed by only updating changed largefiles Historically, during 'hg update', every largefile in the working copy was hashed (which is a very expensive operation on big files) and any largefiles that did not have a hash that matched their standin were updated. This patch optimizes 'hg update' by keeping track of what standins have changed between the old and new revisions, and only updating the largefiles that have changed. This saves a lot of time by avoiding the unecessary calculation of a list of sha1 hashes for big files. With this patch, the time 'hg update' takes to complete is a function of how many largefiles need to be updated and what their size is. Performance tests on a repository with about 80 largefiles ranging from a few MB to about 97 MB are shown below. The tests show how long it takes to run 'hg update' with no changes actually being updated. Mercurial 2.1 release: $ time hg update 0 files updated, 0 files merged, 0 files removed, 0 files unresolved getting changed largefiles 0 largefiles updated, 0 removed real 0m10.045s user 0m9.367s sys 0m0.674s With this patch: $ time hg update 0 files updated, 0 files merged, 0 files removed, 0 files unresolved real 0m0.965s user 0m0.845s sys 0m0.115s The same repsoitory, without the largefiles extension enabled: $ time hg update 0 files updated, 0 files merged, 0 files removed, 0 files unresolved real 0m0.799s user 0m0.684s sys 0m0.111s So before the patch, 'hg update' with no changes was approximately 9.25s slower with largefiles enabled. With this patch, it is approximately 0.165s slower.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14140
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
     1
#!/usr/bin/env python
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
     2
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
     3
# Filter output by pyflakes to control which warnings we check
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
     4
14209
08d84bdce1a5 pyflakes: ignore files marked no-check-code
Augie Fackler <durin42@gmail.com>
parents: 14176
diff changeset
     5
import sys, re, os
14140
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
     6
14173
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
     7
def makekey(message):
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
     8
    # "path/file:line: message"
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
     9
    match = re.search(r"(line \d+)", message)
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    10
    line = ''
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    11
    if match:
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    12
        line = match.group(0)
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    13
        message = re.sub(r"(line \d+)", '', message)
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    14
    return re.sub(r"([^:]*):([^:]+):([^']*)('[^']*')(.*)$",
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    15
                  r'\3:\5:\4:\1:\2:' + line,
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    16
                  message)
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    17
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    18
lines = []
14140
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
    19
for line in sys.stdin:
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
    20
    # We whitelist tests
14175
b452abffcb15 tests: add pyflakes checking for assigned to but never used
timeless <timeless@mozdev.org>
parents: 14173
diff changeset
    21
    pats = [
b452abffcb15 tests: add pyflakes checking for assigned to but never used
timeless <timeless@mozdev.org>
parents: 14173
diff changeset
    22
            r"imported but unused",
b452abffcb15 tests: add pyflakes checking for assigned to but never used
timeless <timeless@mozdev.org>
parents: 14173
diff changeset
    23
            r"local variable '.*' is assigned to but never used",
14176
dea68bddfb87 test: add pyflakes checking for unable to detect undefined names
timeless <timeless@mozdev.org>
parents: 14175
diff changeset
    24
            r"unable to detect undefined names",
14175
b452abffcb15 tests: add pyflakes checking for assigned to but never used
timeless <timeless@mozdev.org>
parents: 14173
diff changeset
    25
           ]
b452abffcb15 tests: add pyflakes checking for assigned to but never used
timeless <timeless@mozdev.org>
parents: 14173
diff changeset
    26
    if not re.search('|'.join(pats), line):
14140
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
    27
        continue
14209
08d84bdce1a5 pyflakes: ignore files marked no-check-code
Augie Fackler <durin42@gmail.com>
parents: 14176
diff changeset
    28
    fn = line.split(':', 1)[0]
08d84bdce1a5 pyflakes: ignore files marked no-check-code
Augie Fackler <durin42@gmail.com>
parents: 14176
diff changeset
    29
    f = open(os.path.join(os.path.dirname(os.path.dirname(__file__)), fn))
08d84bdce1a5 pyflakes: ignore files marked no-check-code
Augie Fackler <durin42@gmail.com>
parents: 14176
diff changeset
    30
    data = f.read()
08d84bdce1a5 pyflakes: ignore files marked no-check-code
Augie Fackler <durin42@gmail.com>
parents: 14176
diff changeset
    31
    f.close()
08d84bdce1a5 pyflakes: ignore files marked no-check-code
Augie Fackler <durin42@gmail.com>
parents: 14176
diff changeset
    32
    if 'no-check-code' in data:
08d84bdce1a5 pyflakes: ignore files marked no-check-code
Augie Fackler <durin42@gmail.com>
parents: 14176
diff changeset
    33
        continue
14173
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    34
    lines.append(line)
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    35
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    36
for line in sorted(lines, key = makekey):
14140
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
    37
    sys.stdout.write(line)
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
    38
print