name-hash: specify initial size for istate.dir_hash table
authorJeff Hostetler <jeffhost@microsoft.com>
Wed, 22 Mar 2017 17:14:20 +0000 (17:14 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 22 Mar 2017 20:41:41 +0000 (13:41 -0700)
Specify an initial size for the istate.dir_hash HashMap matching
the size of the istate.name_hash.

Previously hashmap_init() was given 0, causing a 64 bucket
hashmap to be created. When working with very large
repositories, this would cause numerous rehash() calls to
realloc and rebalance the hashmap. This is especially true
when the worktree is deep, with many directories containing
a few files.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
name-hash.c
index 6d9f23e932559c58c9ebf4679a6035889f726ed2..3f7722a63b19ec102cd9c9272563ef4d78ec67a8 100644 (file)
@@ -120,7 +120,8 @@ static void lazy_init_name_hash(struct index_state *istate)
                return;
        hashmap_init(&istate->name_hash, (hashmap_cmp_fn) cache_entry_cmp,
                        istate->cache_nr);
-       hashmap_init(&istate->dir_hash, (hashmap_cmp_fn) dir_entry_cmp, 0);
+       hashmap_init(&istate->dir_hash, (hashmap_cmp_fn) dir_entry_cmp,
+                       istate->cache_nr);
        for (nr = 0; nr < istate->cache_nr; nr++)
                hash_index_entry(istate, istate->cache[nr]);
        istate->name_hash_initialized = 1;