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.
from __future__ import absolute_import
import cffi
ffi = cffi.FFI()
ffi.set_source("_osutil_cffi", """
#include <sys/attr.h>
#include <sys/vnode.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
typedef struct val_attrs {
uint32_t length;
attribute_set_t returned;
attrreference_t name_info;
fsobj_type_t obj_type;
struct timespec mtime;
uint32_t accessmask;
off_t datalength;
} __attribute__((aligned(4), packed)) val_attrs_t;
""", include_dirs=['mercurial'])
ffi.cdef('''
typedef uint32_t attrgroup_t;
typedef struct attrlist {
uint16_t bitmapcount; /* number of attr. bit sets in list */
uint16_t reserved; /* (to maintain 4-byte alignment) */
attrgroup_t commonattr; /* common attribute group */
attrgroup_t volattr; /* volume attribute group */
attrgroup_t dirattr; /* directory attribute group */
attrgroup_t fileattr; /* file attribute group */
attrgroup_t forkattr; /* fork attribute group */
...;
};
typedef struct attribute_set {
...;
} attribute_set_t;
typedef struct attrreference {
int attr_dataoffset;
int attr_length;
...;
} attrreference_t;
typedef int ... off_t;
typedef struct val_attrs {
uint32_t length;
attribute_set_t returned;
attrreference_t name_info;
uint32_t obj_type;
struct timespec mtime;
uint32_t accessmask;
off_t datalength;
...;
} val_attrs_t;
/* the exact layout of the above struct will be figured out during build time */
typedef int ... time_t;
typedef struct timespec {
time_t tv_sec;
...;
};
int getattrlist(const char* path, struct attrlist * attrList, void * attrBuf,
size_t attrBufSize, unsigned int options);
int getattrlistbulk(int dirfd, struct attrlist * attrList, void * attrBuf,
size_t attrBufSize, uint64_t options);
#define ATTR_BIT_MAP_COUNT ...
#define ATTR_CMN_NAME ...
#define ATTR_CMN_OBJTYPE ...
#define ATTR_CMN_MODTIME ...
#define ATTR_CMN_ACCESSMASK ...
#define ATTR_CMN_ERROR ...
#define ATTR_CMN_RETURNED_ATTRS ...
#define ATTR_FILE_DATALENGTH ...
#define VREG ...
#define VDIR ...
#define VLNK ...
#define VBLK ...
#define VCHR ...
#define VFIFO ...
#define VSOCK ...
#define S_IFMT ...
int open(const char *path, int oflag, int perm);
int close(int);
#define O_RDONLY ...
''')
if __name__ == '__main__':
ffi.compile()