Skip to content

Commit 2821104

Browse files
author
Junio C Hamano
committed
diffcore-delta: make the hash a bit denser.
To reduce wasted memory, wait until the hash fills up more densely before we rehash. This reduces the working set size a bit further. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent c06c796 commit 2821104

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

diffcore-delta.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@
2525
*/
2626

2727
/* Wild guess at the initial hash size */
28-
#define INITIAL_HASH_SIZE 10
28+
#define INITIAL_HASH_SIZE 9
2929
#define HASHBASE 65537 /* next_prime(2^16) */
30+
/* We leave more room in smaller hash but do not let it
31+
* grow to have unused hole too much.
32+
*/
33+
#define INITIAL_FREE(sz_log2) ((1<<(sz_log2))*(sz_log2-3)/(sz_log2))
3034

3135
struct spanhash {
3236
unsigned long hashval;
@@ -38,7 +42,8 @@ struct spanhash_top {
3842
struct spanhash data[FLEX_ARRAY];
3943
};
4044

41-
static struct spanhash *spanhash_find(struct spanhash_top *top, unsigned long hashval)
45+
static struct spanhash *spanhash_find(struct spanhash_top *top,
46+
unsigned long hashval)
4247
{
4348
int sz = 1 << top->alloc_log2;
4449
int bucket = hashval & (sz - 1);
@@ -62,7 +67,7 @@ static struct spanhash_top *spanhash_rehash(struct spanhash_top *orig)
6267

6368
new = xmalloc(sizeof(*orig) + sizeof(struct spanhash) * sz);
6469
new->alloc_log2 = orig->alloc_log2 + 1;
65-
new->free = osz;
70+
new->free = INITIAL_FREE(new->alloc_log2);
6671
memset(new->data, 0, sizeof(struct spanhash) * sz);
6772
for (i = 0; i < osz; i++) {
6873
struct spanhash *o = &(orig->data[i]);
@@ -122,7 +127,7 @@ static struct spanhash_top *hash_chars(unsigned char *buf, unsigned long sz)
122127
i = INITIAL_HASH_SIZE;
123128
hash = xmalloc(sizeof(*hash) + sizeof(struct spanhash) * (1<<i));
124129
hash->alloc_log2 = i;
125-
hash->free = (1<<i)/2;
130+
hash->free = INITIAL_FREE(i);
126131
memset(hash->data, 0, sizeof(struct spanhash) * (1<<i));
127132

128133
/* an 8-byte shift register made of accum1 and accum2. New

diffcore-rename.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ void diffcore_rename(struct diff_options *options)
307307
m->score = estimate_similarity(one, two,
308308
minimum_score);
309309
}
310-
free(two->cnt_data);
311-
two->cnt_data = NULL;
310+
/* We do not need the text anymore */
311+
diff_free_filespec_data(two);
312312
dst_cnt++;
313313
}
314314
/* cost matrix sorted by most to least similar pair */

0 commit comments

Comments
 (0)