summaryrefslogtreecommitdiff
path: root/src/alloc.h
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-03-14 10:43:00 +0000
committerPatrick Steinhardt <ps@pks.im>2018-06-07 12:57:39 +0200
commit08b318c0645b27393a70c2289a65b949ea4b45ed (patch)
tree9d14f5bc43d443b84be0d13699f7488fbebe42d7 /src/alloc.h
parentd2e996fa17c0c39afe32a703a88b5f1f7b256c1c (diff)
downloadlibgit2-08b318c0645b27393a70c2289a65b949ea4b45ed.tar.gz
stdalloc: extend allocators by file and line
Our desired architecture would make allocators completely pluggable, such that users of libgit2 can swap out memory allocators at runtime. While making e.g. debugging easier by not having to do a separate build, this feature can also help maintainers of bindings for libgit2 by tying the memory allocations into the other language's memory system. In order to do so, though, we first need to make our two different pre-existing allocators "stdalloc" and "crtdbg" have the same function signatures, as the "crtdbg" allocators all have an additional file and line argument. This is required to build correct stack traces for debugging memory allocations. As that feature may also be interesting to authors of other applications for debugging libgit2, we now simply add these arguments to our standard allocators. Obviously, this may come with a performance penalty. During some simple benchmarks no real impact could be measured though in contrast to a simple pluggable allocator. The following table summarizes the benchmarks. There were three different builds with our current standard allocator ("standard"), with pluggable authenticators accessed via function pointers ("pluggable") and for pluggable authenticators with file and line being added ("fileline"). Furthermore, there were three scenarios for 100.000.000 allocations of 100B ("small alloc"), 100.000.000 allocations of 100KB ("medium alloc"), and 1.000.000 allocations of 100MB. All results are best of 10 runs. |------------|-------------------|-------------------|-------------------| | build/test | small alloc | medium alloc | big alloc | |------------|-------------------|-------------------|-------------------| | standard | 4539779566, +0.0% | 5912927186, +0.0% | 5166935308, +0.0% | |------------|-------------------|-------------------|-------------------| | pluggable | 4611074505, +1.5% | 5979185308, +1.1% | 5388776352, +4.2% | |------------|-------------------|-------------------|-------------------| | fileline | 4588338192, +1.1% | 6004951910, +1.5% | 4942528135, -4.4% | |------------|-------------------|-------------------|-------------------| As can be seen, there is a performance overhead for pluggable allocators. Furthermore, it can also be seen that there is some big variance between runs, especially in the "big alloc" scenario. This is probably being caused by nondeterministic behaviour in the kernel for dynamic allocations. Still, it can be observed that there should be no real difference between the "pluggable" and "fileline" allocators.
Diffstat (limited to 'src/alloc.h')
-rw-r--r--src/alloc.h16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/alloc.h b/src/alloc.h
index e2dfdbc71..486f1e00d 100644
--- a/src/alloc.h
+++ b/src/alloc.h
@@ -54,14 +54,14 @@
#include "stdalloc.h"
-#define git__malloc(len) git__stdalloc__malloc(len)
-#define git__calloc(nelem, elsize) git__stdalloc__calloc(nelem, elsize)
-#define git__strdup(str) git__stdalloc__strdup(str)
-#define git__strndup(str, n) git__stdalloc__strndup(str, n)
-#define git__substrdup(str, n) git__stdalloc__substrdup(str, n)
-#define git__realloc(ptr, size) git__stdalloc__realloc(ptr, size)
-#define git__reallocarray(ptr, nelem, elsize) git__stdalloc__reallocarray(ptr, nelem, elsize)
-#define git__mallocarray(nelem, elsize) git__stdalloc__mallocarray(nelem, elsize)
+#define git__malloc(len) git__stdalloc__malloc(len, __FILE__, __LINE__)
+#define git__calloc(nelem, elsize) git__stdalloc__calloc(nelem, elsize, __FILE__, __LINE__)
+#define git__strdup(str) git__stdalloc__strdup(str, __FILE__, __LINE__)
+#define git__strndup(str, n) git__stdalloc__strndup(str, n, __FILE__, __LINE__)
+#define git__substrdup(str, n) git__stdalloc__substrdup(str, n, __FILE__, __LINE__)
+#define git__realloc(ptr, size) git__stdalloc__realloc(ptr, size, __FILE__, __LINE__)
+#define git__reallocarray(ptr, nelem, elsize) git__stdalloc__reallocarray(ptr, nelem, elsize, __FILE__, __LINE__)
+#define git__mallocarray(nelem, elsize) git__stdalloc__mallocarray(nelem, elsize, __FILE__, __LINE__)
#define git__free git__stdalloc__free
#endif /* !MSVC_CTRDBG */