Skip to content

Commit d43d579

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 37d9c77 commit d43d579

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
@@ -499,7 +499,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
499499
die_in_unpopulated_submodule(&the_index, prefix);
500500
die_path_inside_submodule(&the_index, &pathspec);
501501

502-
enable_fscache(1);
502+
enable_fscache(0);
503503
/* We do not really re-read the index but update the up-to-date flags */
504504
preload_index(&the_index, &pathspec, 0);
505505

builtin/checkout.c

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

374374
enable_delayed_checkout(&state);
375-
enable_fscache(1);
375+
enable_fscache(active_nr);
376376
for (pos = 0; pos < active_nr; pos++) {
377377
struct cache_entry *ce = active_cache[pos];
378378
if (ce->ce_flags & CE_MATCHED) {
@@ -391,7 +391,7 @@ static int checkout_paths(const struct checkout_opts *opts,
391391
pos = skip_same_name(ce, pos) - 1;
392392
}
393393
}
394-
enable_fscache(0);
394+
disable_fscache();
395395
errs |= finish_delayed_checkout(&state, &nr_checkouts);
396396

397397
if (opts->count_checkout_paths) {

builtin/commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13711371
PATHSPEC_PREFER_FULL,
13721372
prefix, argv);
13731373

1374-
enable_fscache(1);
1374+
enable_fscache(0);
13751375
if (status_format != STATUS_FORMAT_PORCELAIN &&
13761376
status_format != STATUS_FORMAT_PORCELAIN_V2)
13771377
progress_flag = REFRESH_PROGRESS;
@@ -1412,7 +1412,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
14121412
wt_status_print(&s);
14131413
wt_status_collect_free_buffers(&s);
14141414

1415-
enable_fscache(0);
1415+
disable_fscache();
14161416
return 0;
14171417
}
14181418

compat/win32/fscache.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
387387
* Enables or disables the cache. Note that the cache is read-only, changes to
388388
* the working directory are NOT reflected in the cache while enabled.
389389
*/
390-
int fscache_enable(int enable)
390+
int fscache_enable(int enable, size_t initial_size)
391391
{
392392
int result;
393393

@@ -403,7 +403,11 @@ int fscache_enable(int enable)
403403
InitializeCriticalSection(&mutex);
404404
lstat_requests = opendir_requests = 0;
405405
fscache_misses = fscache_requests = 0;
406-
hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, 0);
406+
/*
407+
* avoid having to rehash by leaving room for the parent dirs.
408+
* '4' was determined empirically by testing several repos
409+
*/
410+
hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, initial_size * 4);
407411
initialized = 1;
408412
}
409413

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
@@ -669,7 +669,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
669669

670670
save_commit_buffer = 0;
671671

672-
enable_fscache(1);
672+
enable_fscache(0);
673673
for (ref = *refs; ref; ref = ref->next) {
674674
struct object *o;
675675

@@ -690,7 +690,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
690690
cutoff = commit->date;
691691
}
692692
}
693-
enable_fscache(0);
693+
disable_fscache();
694694

695695
if (!args->deepen) {
696696
for_each_ref(mark_complete_oid, NULL);

git-compat-util.h

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

1291+
#ifndef disable_fscache
1292+
#define disable_fscache() /* noop */
1293+
#endif
1294+
12911295
#ifndef is_fscache_enabled
12921296
#define is_fscache_enabled(path) (0)
12931297
#endif

preload-index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void preload_index(struct index_state *index,
120120
pthread_mutex_init(&pd.mutex, NULL);
121121
}
122122

123-
enable_fscache(1);
123+
enable_fscache(index->cache_nr);
124124
for (i = 0; i < threads; i++) {
125125
struct thread_data *p = data+i;
126126
int err;
@@ -146,7 +146,7 @@ void preload_index(struct index_state *index,
146146
stop_progress(&pd.progress);
147147

148148
trace_performance_leave("preload index");
149-
enable_fscache(0);
149+
disable_fscache();
150150
}
151151

152152
int repo_read_index_preload(struct repository *repo,

read-cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
14951495
typechange_fmt = in_porcelain ? "T\t%s\n" : "%s: needs update\n";
14961496
added_fmt = in_porcelain ? "A\t%s\n" : "%s: needs update\n";
14971497
unmerged_fmt = in_porcelain ? "U\t%s\n" : "%s: needs merge\n";
1498-
enable_fscache(1);
1498+
enable_fscache(0);
14991499
/*
15001500
* Use the multi-threaded preload_index() to refresh most of the
15011501
* cache entries quickly then in the single threaded loop below,
@@ -1573,7 +1573,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
15731573
stop_progress(&progress);
15741574
}
15751575
trace_performance_leave("refresh index");
1576-
enable_fscache(0);
1576+
disable_fscache();
15771577
return has_errors;
15781578
}
15791579

0 commit comments

Comments
 (0)