summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2021-07-30 11:47:39 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-07-30 16:01:18 (GMT)
commit4137c54b902faa640c485dc6d20eaac946e503a5 (patch)
tree134e1111f5c69fde266ebd90face5c2f0c42d59f
parentcdf2241c717b05845ff9e25b87be6ca7559e82eb (diff)
downloadgit-4137c54b902faa640c485dc6d20eaac946e503a5.zip
git-4137c54b902faa640c485dc6d20eaac946e503a5.tar.gz
git-4137c54b902faa640c485dc6d20eaac946e503a5.tar.bz2
merge-ort: set up a memory pool
merge-ort has a lot of data structures, and they all tend to be freed together in clear_or_reinit_internal_opts(). Set up a memory pool to allow us to make these allocations and deallocations faster. Future commits will adjust various callers to make use of this memory pool. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--merge-ort.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/merge-ort.c b/merge-ort.c
index 63f6724..3f42543 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -37,6 +37,8 @@
#include "unpack-trees.h"
#include "xdiff-interface.h"
+#define USE_MEMORY_POOL 1 /* faster, but obscures memory leak hunting */
+
/*
* We have many arrays of size 3. Whenever we have such an array, the
* indices refer to one of the sides of the three-way merge. This is so
@@ -340,6 +342,17 @@ struct merge_options_internal {
struct strmap conflicted;
/*
+ * pool: memory pool for fast allocation/deallocation
+ *
+ * We allocate room for lots of filenames and auxiliary data
+ * structures in merge_options_internal, and it tends to all be
+ * freed together too. Using a memory pool for these provides a
+ * nice speedup.
+ */
+ struct mem_pool internal_pool;
+ struct mem_pool *pool; /* NULL, or pointer to internal_pool */
+
+ /*
* paths_to_free: additional list of strings to free
*
* If keys are removed from "paths", they are added to paths_to_free
@@ -603,6 +616,12 @@ static void clear_or_reinit_internal_opts(struct merge_options_internal *opti,
strmap_clear(&opti->output, 0);
}
+#if USE_MEMORY_POOL
+ mem_pool_discard(&opti->internal_pool, 0);
+ if (!reinitialize)
+ opti->pool = NULL;
+#endif
+
/* Clean out callback_data as well. */
FREE_AND_NULL(renames->callback_data);
renames->callback_data_nr = renames->callback_data_alloc = 0;
@@ -4381,6 +4400,12 @@ static void merge_start(struct merge_options *opt, struct merge_result *result)
/* Initialization of various renames fields */
renames = &opt->priv->renames;
+#if USE_MEMORY_POOL
+ mem_pool_init(&opt->priv->internal_pool, 0);
+ opt->priv->pool = &opt->priv->internal_pool;
+#else
+ opt->priv->pool = NULL;
+#endif
for (i = MERGE_SIDE1; i <= MERGE_SIDE2; i++) {
strintmap_init_with_options(&renames->dirs_removed[i],
NOT_RELEVANT, NULL, 0);