Skip to content

Commit 17e1ed7

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 d553dc5 commit 17e1ed7

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
@@ -462,7 +462,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
462462
die_in_unpopulated_submodule(&the_index, prefix);
463463
die_path_inside_submodule(&the_index, &pathspec);
464464

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

builtin/checkout.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static int checkout_worktree(const struct checkout_opts *opts)
346346
state.istate = &the_index;
347347

348348
enable_delayed_checkout(&state);
349-
enable_fscache(1);
349+
enable_fscache(active_nr);
350350
for (pos = 0; pos < active_nr; pos++) {
351351
struct cache_entry *ce = active_cache[pos];
352352
if (ce->ce_flags & CE_MATCHED) {
@@ -366,7 +366,7 @@ static int checkout_worktree(const struct checkout_opts *opts)
366366
pos = skip_same_name(ce, pos) - 1;
367367
}
368368
}
369-
enable_fscache(0);
369+
disable_fscache();
370370
remove_marked_cache_entries(&the_index, 1);
371371
remove_scheduled_dirs();
372372
errs |= finish_delayed_checkout(&state, &nr_checkouts);

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

673673
save_commit_buffer = 0;
674674

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

@@ -693,7 +693,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
693693
cutoff = commit->date;
694694
}
695695
}
696-
enable_fscache(0);
696+
disable_fscache();
697697

698698
if (!args->deepen) {
699699
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)