mercurial/util.h
author Gregory Szorc <gregory.szorc@gmail.com>
Mon, 22 Aug 2016 21:48:50 -0700
changeset 29830 92ac2baaea86
parent 29444 284d742e5611
child 30091 d576b7394646
permissions -rw-r--r--
revlog: use an LRU cache for delta chain bases Profiling using statprof revealed a hotspot during changegroup application calculating delta chain bases on generaldelta repos. Essentially, revlog._addrevision() was performing a lot of redundant work tracing the delta chain as part of determining when the chain distance was acceptable. This was most pronounced when adding revisions to manifests, which can have delta chains thousands of revisions long. There was a delta chain base cache on revlogs before, but it only captured a single revision. This was acceptable before generaldelta, when _addrevision would build deltas from the previous revision and thus we'd pretty much guarantee a cache hit when resolving the delta chain base on a subsequent _addrevision call. However, it isn't suitable for generaldelta because parent revisions aren't necessarily the last processed revision. This patch converts the delta chain base cache to an LRU dict cache. The cache can hold multiple entries, so generaldelta repos have a higher chance of getting a cache hit. The impact of this change when processing changegroup additions is significant. On a generaldelta conversion of the "mozilla-unified" repo (which contains heads of the main Firefox repositories in chronological order - this means there are lots of transitions between heads in revlog order), this change has the following impact when performing an `hg unbundle` of an uncompressed bundle of the repo: before: 5:42 CPU time after: 4:34 CPU time Most of this time is saved when applying the changelog and manifest revlogs: before: 2:30 CPU time after: 1:17 CPU time That nearly a 50% reduction in CPU time applying changesets and manifests! Applying a gzipped bundle of the same repo (effectively simulating a `hg clone` over HTTP) showed a similar speedup: before: 5:53 CPU time after: 4:46 CPU time Wall time improvements were basically the same as CPU time. I didn't measure explicitly, but it feels like most of the time is saved when processing manifests. This makes sense, as large manifests tend to have very long delta chains and thus benefit the most from this cache. So, this change effectively makes changegroup application (which is used by `hg unbundle`, `hg clone`, `hg pull`, `hg unshelve`, and various other commands) significantly faster when delta chains are long (which can happen on repos with large numbers of files and thus large manifests). In theory, this change can result in more memory utilization. However, we're caching a dict of ints. At most we have 200 ints + Python object overhead per revlog. And, the cache is really only populated when performing read-heavy operations, such as adding changegroups or scanning an individual revlog. For memory bloat to be an issue, we'd need to scan/read several revisions from several revlogs all while having active references to several revlogs. I don't think there are many operations that do this, so I don't think memory bloat from the cache will be an issue.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11358
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     1
/*
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     2
 util.h - utility functions for interfacing with the various python APIs.
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     3
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     4
 This software may be used and distributed according to the terms of
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     5
 the GNU General Public License, incorporated herein by reference.
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     6
*/
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     7
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     8
#ifndef _HG_UTIL_H_
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
     9
#define _HG_UTIL_H_
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    10
29444
284d742e5611 internals: move the bitmanipulation routines into its own file
Maciej Fijalkowski <fijall@gmail.com>
parents: 25076
diff changeset
    11
#include "compat.h"
284d742e5611 internals: move the bitmanipulation routines into its own file
Maciej Fijalkowski <fijall@gmail.com>
parents: 25076
diff changeset
    12
11358
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    13
#if PY_MAJOR_VERSION >= 3
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    14
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    15
#define IS_PY3K
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    16
#define PyInt_FromLong PyLong_FromLong
11534
9777a3b19efe util.h: Add a PyInt_AsLong definition for usage in the inotify module.
Renato Cunha <renatoc@gmail.com>
parents: 11358
diff changeset
    17
#define PyInt_AsLong PyLong_AsLong
11358
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    18
11535
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    19
/*
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    20
 Mapping of some of the python < 2.x PyString* functions to py3k's PyUnicode.
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    21
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    22
 The commented names below represent those that are present in the PyBytes
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    23
 definitions for python < 2.6 (below in this file) that don't have a direct
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    24
 implementation.
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    25
*/
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    26
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    27
#define PyStringObject PyUnicodeObject
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    28
#define PyString_Type PyUnicode_Type
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    29
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    30
#define PyString_Check PyUnicode_Check
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    31
#define PyString_CheckExact PyUnicode_CheckExact
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    32
#define PyString_CHECK_INTERNED PyUnicode_CHECK_INTERNED
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    33
#define PyString_AS_STRING PyUnicode_AsLatin1String
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    34
#define PyString_GET_SIZE PyUnicode_GET_SIZE
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    35
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    36
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    37
#define PyString_FromString PyUnicode_FromString
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    38
#define PyString_FromFormatV PyUnicode_FromFormatV
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    39
#define PyString_FromFormat PyUnicode_FromFormat
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    40
/* #define PyString_Size PyUnicode_GET_SIZE */
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    41
/* #define PyString_AsString */
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    42
/* #define PyString_Repr */
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    43
#define PyString_Concat PyUnicode_Concat
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    44
#define PyString_ConcatAndDel PyUnicode_AppendAndDel
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    45
#define _PyString_Resize PyUnicode_Resize
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    46
/* #define _PyString_Eq */
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    47
#define PyString_Format PyUnicode_Format
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    48
/* #define _PyString_FormatLong */
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    49
/* #define PyString_DecodeEscape */
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    50
#define _PyString_Join PyUnicode_Join
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    51
#define PyString_Decode PyUnicode_Decode
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    52
#define PyString_Encode PyUnicode_Encode
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    53
#define PyString_AsEncodedObject PyUnicode_AsEncodedObject
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    54
#define PyString_AsEncodedString PyUnicode_AsEncodedString
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    55
#define PyString_AsDecodedObject PyUnicode_AsDecodedObject
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    56
#define PyString_AsDecodedString PyUnicode_AsDecodedUnicode
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    57
/* #define PyString_AsStringAndSize */
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    58
#define _PyString_InsertThousandsGrouping _PyUnicode_InsertThousandsGrouping
09cb56b760b4 util.h: Defined macros for working "with" PyStrings in py3k.
Renato Cunha <renatoc@gmail.com>
parents: 11534
diff changeset
    59
11358
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    60
#endif /* PY_MAJOR_VERSION */
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    61
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    62
typedef struct {
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    63
	PyObject_HEAD
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    64
	char state;
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    65
	int mode;
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    66
	int size;
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    67
	int mtime;
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    68
} dirstateTupleObject;
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    69
21838
0022ee690446 util.h: declare dirstateTupleType variable instead of defining it
André Sintzoff <andre.sintzoff@gmail.com>
parents: 21809
diff changeset
    70
extern PyTypeObject dirstateTupleType;
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    71
#define dirstate_tuple_check(op) (Py_TYPE(op) == &dirstateTupleType)
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 19833
diff changeset
    72
24608
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
    73
/* This should be kept in sync with normcasespecs in encoding.py. */
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
    74
enum normcase_spec {
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
    75
	NORMCASE_LOWER = -1,
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
    76
	NORMCASE_UPPER = 1,
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
    77
	NORMCASE_OTHER = 0
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
    78
};
1c533e23ce95 util.h: define an enum for normcase specs
Siddharth Agarwal <sid0@fb.com>
parents: 24443
diff changeset
    79
24443
539b3c7eea44 phase: compute phases in C
Laurent Charignon <lcharignon@fb.com>
parents: 24442
diff changeset
    80
#define MIN(a, b) (((a)<(b))?(a):(b))
24442
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
    81
/* VC9 doesn't include bool and lacks stdbool.h based on my searching */
24829
8e9f8d2a2c0c util: fix the check for non-C99 compilers (issue4605)
Kevin Bullock <kbullock@ringworld.org>
parents: 24823
diff changeset
    82
#if defined(_MSC_VER) || __STDC_VERSION__ < 199901L
24442
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
    83
#define true 1
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
    84
#define false 0
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
    85
typedef unsigned char bool;
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
    86
#else
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
    87
#include <stdbool.h>
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
    88
#endif
98042b0e19f9 manifest: move C bool polyfill into util.h
Matt Mackall <mpm@selenic.com>
parents: 24016
diff changeset
    89
11358
4494fb02d549 util.h: Utility macros for handling different Python APIs.
Renato Cunha <renatoc@gmail.com>
parents:
diff changeset
    90
#endif /* _HG_UTIL_H_ */