setup_bdiff_cffi.py
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Sun, 09 Oct 2016 01:03:17 +0900
changeset 30145 113aa6145020
parent 29833 a8933d992a71
permissions -rw-r--r--
perf: avoid actual writing branch cache out correctly Mercurial 2.5 (or 9b6ae29d4801) introduced "perfbranchmap" command, and tried to avoid actual writing branch cache out by replacing write() of branchcache class in branchmap.py with no-op function (probably, for elimination of noisy and heavy file I/O factor). But its implementation isn't correct, because 9b6ae29d4801 replaced not branchmap.branchcache.write() but branchmap.write(). The latter doesn't exist, even at that change. To avoid actual writing branch cache out correctly, this patch replaces branchmap.branchcache.write() with no-op function. To detect mistake of replacement or change of API in the future quickly, this patch uses safeattrsetter() instead of direct attribute assignment. For similarity between replacements, this patch also changes replacement of branchmap.read(). In this patch, replacement of read()/write() can run safely outside "try" block, because two safeattrsetter() invocations ensure that replacement doesn't cause exception. FYI, the table below compares "base" filter wall time of perfbranchmap on recent mozilla-central repo with each Mercurial version between before and after this patch. ==== ========= ========= ver before after ==== ========= ========= 2.5 18.492334 18.232455 2.6 18.733858 18.156702 2.7 18.245598 18.349210 2.8 18.289070 18.528422 2.9 17.572742 16.989655 3.0 17.406953 17.615012 3.1 17.228419 17.689805 3.2 17.862961 17.718367 3.3 2.632110 2.707960 3.4 3.285683 3.272060 3.5 3.370141 3.352176 3.6 3.366939 3.242455 3.7 3.300778 3.367328 3.8 3.300132 3.267298 3.9 3.418996 3.370265 ==== ========= ========= IMHO, there is no serious overlooking performance regression.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29833
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     1
from __future__ import absolute_import
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     2
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     3
import cffi
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     4
import os
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     5
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     6
ffi = cffi.FFI()
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     7
ffi.set_source("_bdiff_cffi",
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     8
    open(os.path.join(os.path.join(os.path.dirname(__file__), 'mercurial'),
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     9
        'bdiff.c')).read(), include_dirs=['mercurial'])
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    10
ffi.cdef("""
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    11
struct bdiff_line {
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    12
    int hash, n, e;
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    13
    ssize_t len;
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    14
    const char *l;
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    15
};
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    16
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    17
struct bdiff_hunk;
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    18
struct bdiff_hunk {
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    19
    int a1, a2, b1, b2;
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    20
    struct bdiff_hunk *next;
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    21
};
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    22
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    23
int bdiff_splitlines(const char *a, ssize_t len, struct bdiff_line **lr);
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    24
int bdiff_diff(struct bdiff_line *a, int an, struct bdiff_line *b, int bn,
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    25
    struct bdiff_hunk *base);
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    26
void bdiff_freehunks(struct bdiff_hunk *l);
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    27
void free(void*);
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    28
""")
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    29
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    30
if __name__ == '__main__':
a8933d992a71 bdiff: implement cffi version of blocks
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    31
    ffi.compile()