Skip to content

Commit 4137c54

Browse files
newrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cdf2241 commit 4137c54

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

merge-ort.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include "unpack-trees.h"
3838
#include "xdiff-interface.h"
3939

40+
#define USE_MEMORY_POOL 1 /* faster, but obscures memory leak hunting */
41+
4042
/*
4143
* We have many arrays of size 3. Whenever we have such an array, the
4244
* indices refer to one of the sides of the three-way merge. This is so
@@ -339,6 +341,17 @@ struct merge_options_internal {
339341
*/
340342
struct strmap conflicted;
341343

344+
/*
345+
* pool: memory pool for fast allocation/deallocation
346+
*
347+
* We allocate room for lots of filenames and auxiliary data
348+
* structures in merge_options_internal, and it tends to all be
349+
* freed together too. Using a memory pool for these provides a
350+
* nice speedup.
351+
*/
352+
struct mem_pool internal_pool;
353+
struct mem_pool *pool; /* NULL, or pointer to internal_pool */
354+
342355
/*
343356
* paths_to_free: additional list of strings to free
344357
*
@@ -603,6 +616,12 @@ static void clear_or_reinit_internal_opts(struct merge_options_internal *opti,
603616
strmap_clear(&opti->output, 0);
604617
}
605618

619+
#if USE_MEMORY_POOL
620+
mem_pool_discard(&opti->internal_pool, 0);
621+
if (!reinitialize)
622+
opti->pool = NULL;
623+
#endif
624+
606625
/* Clean out callback_data as well. */
607626
FREE_AND_NULL(renames->callback_data);
608627
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)
43814400

43824401
/* Initialization of various renames fields */
43834402
renames = &opt->priv->renames;
4403+
#if USE_MEMORY_POOL
4404+
mem_pool_init(&opt->priv->internal_pool, 0);
4405+
opt->priv->pool = &opt->priv->internal_pool;
4406+
#else
4407+
opt->priv->pool = NULL;
4408+
#endif
43844409
for (i = MERGE_SIDE1; i <= MERGE_SIDE2; i++) {
43854410
strintmap_init_with_options(&renames->dirs_removed[i],
43864411
NOT_RELEVANT, NULL, 0);

0 commit comments

Comments
 (0)