Skip to content

Commit fdb28f0

Browse files
benpeartdscho
authored andcommitted
fscache: fscache takes an initial size
Update enable_fscache() to take an optional initial size parameter which is used to initialize the hashmap so that it can avoid having to rehash as additional entries are added. Add a separate disable_fscache() macro to make the code clearer and easier to read. Signed-off-by: Ben Peart <[email protected]>
1 parent 824ea00 commit fdb28f0

File tree

9 files changed

+24
-15
lines changed

9 files changed

+24
-15
lines changed

builtin/add.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
461461

462462
die_path_inside_submodule(&the_index, &pathspec);
463463

464-
enable_fscache(1);
464+
enable_fscache(0);
465465
/* We do not really re-read the index but update the up-to-date flags */
466466
preload_index(&the_index, &pathspec);
467467

builtin/checkout.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static int checkout_paths(const struct checkout_opts *opts,
360360
state.istate = &the_index;
361361

362362
enable_delayed_checkout(&state);
363-
enable_fscache(1);
363+
enable_fscache(active_nr);
364364
for (pos = 0; pos < active_nr; pos++) {
365365
struct cache_entry *ce = active_cache[pos];
366366
if (ce->ce_flags & CE_MATCHED) {
@@ -375,7 +375,7 @@ static int checkout_paths(const struct checkout_opts *opts,
375375
pos = skip_same_name(ce, pos) - 1;
376376
}
377377
}
378-
enable_fscache(0);
378+
disable_fscache();
379379
errs |= finish_delayed_checkout(&state);
380380

381381
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))

builtin/commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13771377
PATHSPEC_PREFER_FULL,
13781378
prefix, argv);
13791379

1380-
enable_fscache(1);
1380+
enable_fscache(0);
13811381
read_cache_preload(&s.pathspec);
13821382
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
13831383

@@ -1411,7 +1411,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
14111411
s.prefix = prefix;
14121412

14131413
wt_status_print(&s);
1414-
enable_fscache(0);
1414+
disable_fscache();
14151415
return 0;
14161416
}
14171417

compat/win32/fscache.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
401401
* Enables or disables the cache. Note that the cache is read-only, changes to
402402
* the working directory are NOT reflected in the cache while enabled.
403403
*/
404-
int fscache_enable(int enable)
404+
int fscache_enable(int enable, size_t initial_size)
405405
{
406406
int result;
407407

@@ -417,7 +417,11 @@ int fscache_enable(int enable)
417417
InitializeCriticalSection(&mutex);
418418
lstat_requests = opendir_requests = 0;
419419
fscache_misses = fscache_requests = 0;
420-
hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, 0);
420+
/*
421+
* avoid having to rehash by leaving room for the parent dirs.
422+
* '4' was determined empirically by testing several repos
423+
*/
424+
hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, initial_size * 4);
421425
initialized = 1;
422426
}
423427

compat/win32/fscache.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#ifndef FSCACHE_H
22
#define FSCACHE_H
33

4-
int fscache_enable(int enable);
5-
#define enable_fscache(x) fscache_enable(x)
4+
int fscache_enable(int enable, size_t initial_size);
5+
#define enable_fscache(initial_size) fscache_enable(1, initial_size)
6+
#define disable_fscache() fscache_enable(0, 0)
67

78
int fscache_enabled(const char *path);
89
#define is_fscache_enabled(path) fscache_enabled(path)

fetch-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
684684

685685
save_commit_buffer = 0;
686686

687-
enable_fscache(1);
687+
enable_fscache(0);
688688
for (ref = *refs; ref; ref = ref->next) {
689689
struct object *o;
690690
unsigned int flags = OBJECT_INFO_QUICK;
@@ -714,7 +714,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
714714
cutoff = commit->date;
715715
}
716716
}
717-
enable_fscache(0);
717+
disable_fscache();
718718

719719
oidset_clear(&loose_oid_set);
720720

git-compat-util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,10 @@ static inline int is_missing_file_error(int errno_)
12591259
#define enable_fscache(x) /* noop */
12601260
#endif
12611261

1262+
#ifndef disable_fscache
1263+
#define disable_fscache() /* noop */
1264+
#endif
1265+
12621266
#ifndef is_fscache_enabled
12631267
#define is_fscache_enabled(path) (0)
12641268
#endif

preload-index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void preload_index(struct index_state *index, const struct pathspec *pathspec)
9191
offset = 0;
9292
work = DIV_ROUND_UP(index->cache_nr, threads);
9393
memset(&data, 0, sizeof(data));
94-
enable_fscache(1);
94+
enable_fscache(index->cache_nr);
9595
for (i = 0; i < threads; i++) {
9696
struct thread_data *p = data+i;
9797
p->index = index;
@@ -109,7 +109,7 @@ void preload_index(struct index_state *index, const struct pathspec *pathspec)
109109
die("unable to join threaded lstat");
110110
}
111111
trace_performance_since(start, "preload index");
112-
enable_fscache(0);
112+
disable_fscache();
113113
}
114114
#endif
115115

read-cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
14831483
typechange_fmt = (in_porcelain ? "T\t%s\n" : "%s needs update\n");
14841484
added_fmt = (in_porcelain ? "A\t%s\n" : "%s needs update\n");
14851485
unmerged_fmt = (in_porcelain ? "U\t%s\n" : "%s: needs merge\n");
1486-
enable_fscache(1);
1486+
enable_fscache(0);
14871487
for (i = 0; i < istate->cache_nr; i++) {
14881488
struct cache_entry *ce, *new_entry;
14891489
int cache_errno = 0;
@@ -1548,7 +1548,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
15481548

15491549
replace_index_entry(istate, i, new_entry);
15501550
}
1551-
enable_fscache(0);
1551+
disable_fscache();
15521552
trace_performance_since(start, "refresh index");
15531553
return has_errors;
15541554
}

0 commit comments

Comments
 (0)