Skip to content

Commit cf82571

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 9cd9714 commit cf82571

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
@@ -1363,7 +1363,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13631363
PATHSPEC_PREFER_FULL,
13641364
prefix, argv);
13651365

1366-
enable_fscache(1);
1366+
enable_fscache(0);
13671367
if (status_format != STATUS_FORMAT_PORCELAIN &&
13681368
status_format != STATUS_FORMAT_PORCELAIN_V2)
13691369
progress_flag = REFRESH_PROGRESS;
@@ -1404,7 +1404,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
14041404
wt_status_print(&s);
14051405
wt_status_collect_free_buffers(&s);
14061406

1407-
enable_fscache(0);
1407+
disable_fscache();
14081408
return 0;
14091409
}
14101410

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
@@ -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
@@ -1261,6 +1261,10 @@ static inline int is_missing_file_error(int errno_)
12611261
#define enable_fscache(x) /* noop */
12621262
#endif
12631263

1264+
#ifndef disable_fscache
1265+
#define disable_fscache() /* noop */
1266+
#endif
1267+
12641268
#ifndef is_fscache_enabled
12651269
#define is_fscache_enabled(path) (0)
12661270
#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)