Skip to content

Commit f2c9c4c

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 b87c51e commit f2c9c4c

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

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

builtin/checkout.c

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

369369
enable_delayed_checkout(&state);
370-
enable_fscache(1);
370+
enable_fscache(active_nr);
371371
for (pos = 0; pos < active_nr; pos++) {
372372
struct cache_entry *ce = active_cache[pos];
373373
if (ce->ce_flags & CE_MATCHED) {
@@ -382,7 +382,7 @@ static int checkout_paths(const struct checkout_opts *opts,
382382
pos = skip_same_name(ce, pos) - 1;
383383
}
384384
}
385-
enable_fscache(0);
385+
disable_fscache();
386386
errs |= finish_delayed_checkout(&state);
387387

388388
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
@@ -1384,7 +1384,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13841384
PATHSPEC_PREFER_FULL,
13851385
prefix, argv);
13861386

1387-
enable_fscache(1);
1387+
enable_fscache(0);
13881388
if (status_format != STATUS_FORMAT_PORCELAIN &&
13891389
status_format != STATUS_FORMAT_PORCELAIN_V2)
13901390
progress_flag = REFRESH_PROGRESS;
@@ -1425,7 +1425,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
14251425
wt_status_print(&s);
14261426
wt_status_collect_free_buffers(&s);
14271427

1428-
enable_fscache(0);
1428+
disable_fscache();
14291429
return 0;
14301430
}
14311431

compat/win32/fscache.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
410410
* Enables or disables the cache. Note that the cache is read-only, changes to
411411
* the working directory are NOT reflected in the cache while enabled.
412412
*/
413-
int fscache_enable(int enable)
413+
int fscache_enable(int enable, size_t initial_size)
414414
{
415415
int result;
416416

@@ -426,7 +426,11 @@ int fscache_enable(int enable)
426426
InitializeCriticalSection(&mutex);
427427
lstat_requests = opendir_requests = 0;
428428
fscache_misses = fscache_requests = 0;
429-
hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, 0);
429+
/*
430+
* avoid having to rehash by leaving room for the parent dirs.
431+
* '4' was determined empirically by testing several repos
432+
*/
433+
hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, initial_size * 4);
430434
initialized = 1;
431435
}
432436

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

681681
save_commit_buffer = 0;
682682

683-
enable_fscache(1);
683+
enable_fscache(0);
684684
for (ref = *refs; ref; ref = ref->next) {
685685
struct object *o;
686686
unsigned int flags = OBJECT_INFO_QUICK;
@@ -710,7 +710,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
710710
cutoff = commit->date;
711711
}
712712
}
713-
enable_fscache(0);
713+
disable_fscache();
714714

715715
oidset_clear(&loose_oid_set);
716716

git-compat-util.h

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

1268+
#ifndef disable_fscache
1269+
#define disable_fscache() /* noop */
1270+
#endif
1271+
12681272
#ifndef is_fscache_enabled
12691273
#define is_fscache_enabled(path) (0)
12701274
#endif

preload-index.c

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

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

147147
trace_performance_leave("preload index");
148-
enable_fscache(0);
148+
disable_fscache();
149149
}
150150

151151
int read_index_preload(struct index_state *index,

read-cache.c

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

0 commit comments

Comments
 (0)