Skip to content

Commit e920a5b

Browse files
committed
fixup! Merge pull request #964 from jeffhostetler/jeffhostetler/memihash_perf
I should really implement special-handling for a new drop! prefix to commit messages... This commit reverts that Pull Request, in preparation for merging in a new iteration of that work (which looks substantially different from the previous iteration...). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 9975bd0 commit e920a5b

File tree

6 files changed

+16
-145
lines changed

6 files changed

+16
-145
lines changed

cache.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ struct cache_entry {
173173
unsigned int ce_flags;
174174
unsigned int ce_namelen;
175175
unsigned int index; /* for link extension */
176-
unsigned int precompute_hash_state;
177-
unsigned int precompute_hash_name;
178-
unsigned int precompute_hash_dir;
179176
struct object_id oid;
180177
char name[FLEX_ARRAY]; /* more */
181178
};
@@ -232,19 +229,6 @@ struct cache_entry {
232229
#error "CE_EXTENDED_FLAGS out of range"
233230
#endif
234231

235-
/*
236-
* Bit set if preload-index precomputed the hash value(s)
237-
* for this cache-entry.
238-
*/
239-
#define CE_PRECOMPUTE_HASH_STATE__SET (1 << 0)
240-
/*
241-
* Bit set if precompute-index also precomputed the hash value
242-
* for the parent directory.
243-
*/
244-
#define CE_PRECOMPUTE_HASH_STATE__DIR (1 << 1)
245-
246-
void precompute_istate_hashes(struct cache_entry *ce);
247-
248232
/* Forward structure decls */
249233
struct pathspec;
250234
struct child_process;

hashmap.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,6 @@ unsigned int memihash(const void *buf, size_t len)
5050
return hash;
5151
}
5252

53-
/*
54-
* Incoporate another chunk of data into a memihash
55-
* computation.
56-
*/
57-
unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len)
58-
{
59-
unsigned int hash = hash_seed;
60-
unsigned char *ucbuf = (unsigned char *) buf;
61-
while (len--) {
62-
unsigned int c = *ucbuf++;
63-
if (c >= 'a' && c <= 'z')
64-
c -= 'a' - 'A';
65-
hash = (hash * FNV32_PRIME) ^ c;
66-
}
67-
return hash;
68-
}
69-
7053
#define HASHMAP_INITIAL_SIZE 64
7154
/* grow / shrink by 2^2 */
7255
#define HASHMAP_RESIZE_BITS 2

hashmap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ extern unsigned int strhash(const char *buf);
1212
extern unsigned int strihash(const char *buf);
1313
extern unsigned int memhash(const void *buf, size_t len);
1414
extern unsigned int memihash(const void *buf, size_t len);
15-
extern unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len);
1615

1716
static inline unsigned int sha1hash(const unsigned char *sha1)
1817
{

name-hash.c

Lines changed: 16 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,17 @@ static int dir_entry_cmp(const struct dir_entry *e1,
2323
name ? name : e2->name, e1->namelen);
2424
}
2525

26-
static struct dir_entry *find_dir_entry__hash(struct index_state *istate,
27-
const char *name, unsigned int namelen, unsigned int hash)
26+
static struct dir_entry *find_dir_entry(struct index_state *istate,
27+
const char *name, unsigned int namelen)
2828
{
2929
struct dir_entry key;
30-
hashmap_entry_init(&key, hash);
30+
hashmap_entry_init(&key, memihash(name, namelen));
3131
key.namelen = namelen;
3232
return hashmap_get(&istate->dir_hash, &key, name);
3333
}
3434

35-
static struct dir_entry *find_dir_entry(struct index_state *istate,
36-
const char *name, unsigned int namelen)
37-
{
38-
return find_dir_entry__hash(istate, name, namelen, memihash(name,namelen));
39-
}
40-
4135
static struct dir_entry *hash_dir_entry(struct index_state *istate,
42-
struct cache_entry *ce, int namelen, struct dir_entry **p_previous_dir)
36+
struct cache_entry *ce, int namelen)
4337
{
4438
/*
4539
* Throw each directory component in the hash for quick lookup
@@ -49,18 +43,6 @@ static struct dir_entry *hash_dir_entry(struct index_state *istate,
4943
* in index_state.name_hash (as ordinary cache_entries).
5044
*/
5145
struct dir_entry *dir;
52-
unsigned int hash;
53-
int use_precomputed_dir_hash = 0;
54-
55-
if (ce->precompute_hash_state & CE_PRECOMPUTE_HASH_STATE__SET) {
56-
if (!(ce->precompute_hash_state & CE_PRECOMPUTE_HASH_STATE__DIR))
57-
return NULL; /* item does not have a parent directory */
58-
if (namelen == ce_namelen(ce)) {
59-
/* dir hash only valid for outer-most call (not recursive ones) */
60-
use_precomputed_dir_hash = 1;
61-
hash = ce->precompute_hash_dir;
62-
}
63-
}
6446

6547
/* get length of parent directory */
6648
while (namelen > 0 && !is_dir_sep(ce->name[namelen - 1]))
@@ -70,43 +52,24 @@ static struct dir_entry *hash_dir_entry(struct index_state *istate,
7052
namelen--;
7153

7254
/* lookup existing entry for that directory */
73-
if (p_previous_dir && *p_previous_dir
74-
&& namelen == (*p_previous_dir)->namelen
75-
&& memcmp(ce->name, (*p_previous_dir)->name, namelen) == 0) {
76-
/*
77-
* When our caller is sequentially iterating thru the index,
78-
* items in the same directory will be sequential, and therefore
79-
* refer to the same dir_entry.
80-
*/
81-
dir = *p_previous_dir;
82-
} else {
83-
if (!use_precomputed_dir_hash)
84-
hash = memihash(ce->name, namelen);
85-
dir = find_dir_entry__hash(istate, ce->name, namelen, hash);
86-
}
87-
55+
dir = find_dir_entry(istate, ce->name, namelen);
8856
if (!dir) {
8957
/* not found, create it and add to hash table */
9058
FLEX_ALLOC_MEM(dir, name, ce->name, namelen);
91-
hashmap_entry_init(dir, hash);
59+
hashmap_entry_init(dir, memihash(ce->name, namelen));
9260
dir->namelen = namelen;
9361
hashmap_add(&istate->dir_hash, dir);
9462

9563
/* recursively add missing parent directories */
96-
dir->parent = hash_dir_entry(istate, ce, namelen, NULL);
64+
dir->parent = hash_dir_entry(istate, ce, namelen);
9765
}
98-
99-
if (p_previous_dir)
100-
*p_previous_dir = dir;
101-
10266
return dir;
10367
}
10468

105-
static void add_dir_entry(struct index_state *istate, struct cache_entry *ce,
106-
struct dir_entry **p_previous_dir)
69+
static void add_dir_entry(struct index_state *istate, struct cache_entry *ce)
10770
{
10871
/* Add reference to the directory entry (and parents if 0). */
109-
struct dir_entry *dir = hash_dir_entry(istate, ce, ce_namelen(ce), p_previous_dir);
72+
struct dir_entry *dir = hash_dir_entry(istate, ce, ce_namelen(ce));
11073
while (dir && !(dir->nr++))
11174
dir = dir->parent;
11275
}
@@ -117,7 +80,7 @@ static void remove_dir_entry(struct index_state *istate, struct cache_entry *ce)
11780
* Release reference to the directory entry. If 0, remove and continue
11881
* with parent directory.
11982
*/
120-
struct dir_entry *dir = hash_dir_entry(istate, ce, ce_namelen(ce), NULL);
83+
struct dir_entry *dir = hash_dir_entry(istate, ce, ce_namelen(ce));
12184
while (dir && !(--dir->nr)) {
12285
struct dir_entry *parent = dir->parent;
12386
hashmap_remove(&istate->dir_hash, dir, NULL);
@@ -126,25 +89,16 @@ static void remove_dir_entry(struct index_state *istate, struct cache_entry *ce)
12689
}
12790
}
12891

129-
static void hash_index_entry(struct index_state *istate, struct cache_entry *ce,
130-
struct dir_entry **p_previous_dir)
92+
static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
13193
{
132-
unsigned int h;
133-
13494
if (ce->ce_flags & CE_HASHED)
13595
return;
13696
ce->ce_flags |= CE_HASHED;
137-
138-
if (ce->precompute_hash_state & CE_PRECOMPUTE_HASH_STATE__SET)
139-
h = ce->precompute_hash_name;
140-
else
141-
h = memihash(ce->name, ce_namelen(ce));
142-
143-
hashmap_entry_init(ce, h);
97+
hashmap_entry_init(ce, memihash(ce->name, ce_namelen(ce)));
14498
hashmap_add(&istate->name_hash, ce);
14599

146100
if (ignore_case)
147-
add_dir_entry(istate, ce, p_previous_dir);
101+
add_dir_entry(istate, ce);
148102
}
149103

150104
static int cache_entry_cmp(const struct cache_entry *ce1,
@@ -160,24 +114,22 @@ static int cache_entry_cmp(const struct cache_entry *ce1,
160114

161115
static void lazy_init_name_hash(struct index_state *istate)
162116
{
163-
struct dir_entry *previous_dir = NULL;
164117
int nr;
165118

166119
if (istate->name_hash_initialized)
167120
return;
168121
hashmap_init(&istate->name_hash, (hashmap_cmp_fn) cache_entry_cmp,
169122
istate->cache_nr);
170-
hashmap_init(&istate->dir_hash, (hashmap_cmp_fn) dir_entry_cmp,
171-
istate->cache_nr);
123+
hashmap_init(&istate->dir_hash, (hashmap_cmp_fn) dir_entry_cmp, 0);
172124
for (nr = 0; nr < istate->cache_nr; nr++)
173-
hash_index_entry(istate, istate->cache[nr], &previous_dir);
125+
hash_index_entry(istate, istate->cache[nr]);
174126
istate->name_hash_initialized = 1;
175127
}
176128

177129
void add_name_hash(struct index_state *istate, struct cache_entry *ce)
178130
{
179131
if (istate->name_hash_initialized)
180-
hash_index_entry(istate, ce, NULL);
132+
hash_index_entry(istate, ce);
181133
}
182134

183135
void remove_name_hash(struct index_state *istate, struct cache_entry *ce)
@@ -284,45 +236,3 @@ void free_name_hash(struct index_state *istate)
284236
hashmap_free(&istate->name_hash, 0);
285237
hashmap_free(&istate->dir_hash, 1);
286238
}
287-
288-
/*
289-
* Precompute the hash values for this cache_entry
290-
* for use in the istate.name_hash and istate.dir_hash.
291-
*
292-
* If the item is in the root directory, just compute the
293-
* hash value (for istate.name_hash) on the full path.
294-
*
295-
* If the item is in a subdirectory, first compute the
296-
* hash value for the immediate parent directory (for
297-
* istate.dir_hash) and then the hash value for the full
298-
* path by continuing the computation.
299-
*
300-
* Note that these hashes will be used by
301-
* wt_status_collect_untracked() as it scans the worktree
302-
* and maps observed paths back to the index (optionally
303-
* ignoring case). Therefore, we probably only *NEED* to
304-
* precompute this for non-skip-worktree items (since
305-
* status should not observe skipped items), but because
306-
* lazy_init_name_hash() hashes everything, we force it
307-
* here.
308-
*/
309-
void precompute_istate_hashes(struct cache_entry *ce)
310-
{
311-
int namelen = ce_namelen(ce);
312-
313-
while (namelen > 0 && !is_dir_sep(ce->name[namelen - 1]))
314-
namelen--;
315-
316-
if (namelen <= 0) {
317-
ce->precompute_hash_name = memihash(ce->name, ce_namelen(ce));
318-
ce->precompute_hash_state = CE_PRECOMPUTE_HASH_STATE__SET;
319-
} else {
320-
namelen--;
321-
ce->precompute_hash_dir = memihash(ce->name, namelen);
322-
ce->precompute_hash_name = memihash_cont(
323-
ce->precompute_hash_dir, &ce->name[namelen],
324-
ce_namelen(ce) - namelen);
325-
ce->precompute_hash_state =
326-
CE_PRECOMPUTE_HASH_STATE__SET | CE_PRECOMPUTE_HASH_STATE__DIR;
327-
}
328-
}

preload-index.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ static void *preload_thread(void *_data)
4646
struct cache_entry *ce = *cep++;
4747
struct stat st;
4848

49-
precompute_istate_hashes(ce);
50-
5149
if (ce_stage(ce))
5250
continue;
5351
if (S_ISGITLINK(ce->ce_mode))

read-cache.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ void rename_index_entry_at(struct index_state *istate, int nr, const char *new_n
7777
copy_cache_entry(new, old);
7878
new->ce_flags &= ~CE_HASHED;
7979
new->ce_namelen = namelen;
80-
new->precompute_hash_state = 0;
8180
new->index = 0;
8281
memcpy(new->name, new_name, namelen + 1);
8382

@@ -619,7 +618,6 @@ static struct cache_entry *create_alias_ce(struct index_state *istate,
619618
new = xcalloc(1, cache_entry_size(len));
620619
memcpy(new->name, alias->name, len);
621620
copy_cache_entry(new, ce);
622-
new->precompute_hash_state = 0;
623621
save_or_free_index_entry(istate, ce);
624622
return new;
625623
}
@@ -1550,7 +1548,6 @@ static struct cache_entry *cache_entry_from_ondisk(struct ondisk_cache_entry *on
15501548
ce->ce_stat_data.sd_size = get_be32(&ondisk->size);
15511549
ce->ce_flags = flags & ~CE_NAMEMASK;
15521550
ce->ce_namelen = len;
1553-
ce->precompute_hash_state = 0;
15541551
ce->index = 0;
15551552
hashcpy(ce->oid.hash, ondisk->sha1);
15561553
memcpy(ce->name, name, len);

0 commit comments

Comments
 (0)