Skip to content

Commit ce5877f

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 03d083d commit ce5877f

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

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

builtin/checkout.c

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

416416
enable_delayed_checkout(&state);
417-
enable_fscache(1);
417+
enable_fscache(active_nr);
418418
for (pos = 0; pos < active_nr; pos++) {
419419
struct cache_entry *ce = active_cache[pos];
420420
if (ce->ce_flags & CE_MATCHED) {
@@ -434,7 +434,7 @@ static int checkout_paths(const struct checkout_opts *opts,
434434
pos = skip_same_name(ce, pos) - 1;
435435
}
436436
}
437-
enable_fscache(0);
437+
disable_fscache();
438438
remove_marked_cache_entries(&the_index, 1);
439439
remove_scheduled_dirs();
440440
errs |= finish_delayed_checkout(&state, &nr_checkouts);

builtin/commit.c

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

1379-
enable_fscache(1);
1379+
enable_fscache(0);
13801380
if (status_format != STATUS_FORMAT_PORCELAIN &&
13811381
status_format != STATUS_FORMAT_PORCELAIN_V2)
13821382
progress_flag = REFRESH_PROGRESS;
@@ -1417,7 +1417,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
14171417
wt_status_print(&s);
14181418
wt_status_collect_free_buffers(&s);
14191419

1420-
enable_fscache(0);
1420+
disable_fscache();
14211421
return 0;
14221422
}
14231423

compat/win32/fscache.c

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

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

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

672672
save_commit_buffer = 0;
673673

674-
enable_fscache(1);
674+
enable_fscache(0);
675675
for (ref = *refs; ref; ref = ref->next) {
676676
struct object *o;
677677

@@ -692,7 +692,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
692692
cutoff = commit->date;
693693
}
694694
}
695-
enable_fscache(0);
695+
disable_fscache();
696696

697697
if (!args->deepen) {
698698
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
@@ -1298,6 +1298,10 @@ static inline int is_missing_file_error(int errno_)
12981298
#define enable_fscache(x) /* noop */
12991299
#endif
13001300

1301+
#ifndef disable_fscache
1302+
#define disable_fscache() /* noop */
1303+
#endif
1304+
13011305
#ifndef is_fscache_enabled
13021306
#define is_fscache_enabled(path) (0)
13031307
#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
@@ -1505,7 +1505,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
15051505
typechange_fmt = in_porcelain ? "T\t%s\n" : "%s: needs update\n";
15061506
added_fmt = in_porcelain ? "A\t%s\n" : "%s: needs update\n";
15071507
unmerged_fmt = in_porcelain ? "U\t%s\n" : "%s: needs merge\n";
1508-
enable_fscache(1);
1508+
enable_fscache(0);
15091509
/*
15101510
* Use the multi-threaded preload_index() to refresh most of the
15111511
* cache entries quickly then in the single threaded loop below,
@@ -1583,7 +1583,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
15831583
stop_progress(&progress);
15841584
}
15851585
trace_performance_leave("refresh index");
1586-
enable_fscache(0);
1586+
disable_fscache();
15871587
return has_errors;
15881588
}
15891589

0 commit comments

Comments
 (0)