Skip to content

Commit 77434e7

Browse files
Takuto Ikutadscho
Takuto Ikuta
authored andcommitted
checkout.c: enable fscache for checkout again
This is retry of #1419. I added flush_fscache macro to flush cached stats after disk writing with tests for regression reported in #1438 and #1442. git checkout checks each file path in sorted order, so cache flushing does not make performance worse unless we have large number of modified files in a directory containing many files. Using chromium repository, I tested `git checkout .` performance when I delete 10 files in different directories. With this patch: TotalSeconds: 4.307272 TotalSeconds: 4.4863595 TotalSeconds: 4.2975562 Avg: 4.36372923333333 Without this patch: TotalSeconds: 20.9705431 TotalSeconds: 22.4867685 TotalSeconds: 18.8968292 Avg: 20.7847136 I confirmed this patch passed all tests in t/ with core_fscache=1. Signed-off-by: Takuto Ikuta <[email protected]>
1 parent 973b161 commit 77434e7

File tree

7 files changed

+61
-0
lines changed

7 files changed

+61
-0
lines changed

builtin/checkout.c

+2
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
392392
if (pc_workers > 1)
393393
init_parallel_checkout();
394394

395+
enable_fscache(1);
395396
for (pos = 0; pos < the_index.cache_nr; pos++) {
396397
struct cache_entry *ce = the_index.cache[pos];
397398
if (ce->ce_flags & CE_MATCHED) {
@@ -416,6 +417,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
416417
errs |= run_parallel_checkout(&state, pc_workers, pc_threshold,
417418
NULL, NULL);
418419
mem_pool_discard(&ce_mem_pool, should_validate_cache_entries());
420+
enable_fscache(0);
419421
remove_marked_cache_entries(&the_index, 1);
420422
remove_scheduled_dirs();
421423
errs |= finish_delayed_checkout(&state, opts->show_progress);

compat/win32/fscache.c

+12
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,18 @@ int fscache_enable(int enable)
426426
return result;
427427
}
428428

429+
/*
430+
* Flush cached stats result when fscache is enabled.
431+
*/
432+
void fscache_flush(void)
433+
{
434+
if (enabled) {
435+
EnterCriticalSection(&mutex);
436+
fscache_clear();
437+
LeaveCriticalSection(&mutex);
438+
}
439+
}
440+
429441
/*
430442
* Lstat replacement, uses the cache if enabled, otherwise redirects to
431443
* mingw_lstat.

compat/win32/fscache.h

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ int fscache_enable(int enable);
77
int fscache_enabled(const char *path);
88
#define is_fscache_enabled(path) fscache_enabled(path)
99

10+
void fscache_flush(void);
11+
#define flush_fscache() fscache_flush()
12+
1013
DIR *fscache_opendir(const char *dir);
1114
int fscache_lstat(const char *file_name, struct stat *buf);
1215

entry.c

+3
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ static int write_entry(struct cache_entry *ce, char *path, struct conv_attrs *ca
393393
}
394394

395395
finish:
396+
/* Flush cached lstat in fscache after writing to disk. */
397+
flush_fscache();
398+
396399
if (state->refresh_cache) {
397400
if (!fstat_done && lstat(ce->name, &st) < 0)
398401
return error_errno("unable to stat just-written file %s",

git-compat-util.h

+4
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,10 @@ static inline int is_missing_file_error(int errno_)
15561556
#define is_fscache_enabled(path) (0)
15571557
#endif
15581558

1559+
#ifndef flush_fscache
1560+
#define flush_fscache() /* noop */
1561+
#endif
1562+
15591563
int cmd_main(int, const char **);
15601564

15611565
/*

parallel-checkout.c

+1
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ static void write_items_sequentially(struct checkout *state)
637637
{
638638
size_t i;
639639

640+
flush_fscache();
640641
for (i = 0; i < parallel_checkout.nr; i++) {
641642
struct parallel_checkout_item *pc_item = &parallel_checkout.items[i];
642643
write_pc_item(pc_item, state);

t/t7201-co.sh

+36
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,42 @@ fill () {
3535
}
3636

3737

38+
test_expect_success MINGW 'fscache flush cache' '
39+
40+
git init fscache-test &&
41+
cd fscache-test &&
42+
git config core.fscache 1 &&
43+
echo A > test.txt &&
44+
git add test.txt &&
45+
git commit -m A &&
46+
echo B >> test.txt &&
47+
git checkout . &&
48+
test -z "$(git status -s)" &&
49+
echo A > expect.txt &&
50+
test_cmp expect.txt test.txt &&
51+
cd .. &&
52+
rm -rf fscache-test
53+
'
54+
55+
test_expect_success MINGW 'fscache flush cache dir' '
56+
57+
git init fscache-test &&
58+
cd fscache-test &&
59+
git config core.fscache 1 &&
60+
echo A > test.txt &&
61+
git add test.txt &&
62+
git commit -m A &&
63+
rm test.txt &&
64+
mkdir test.txt &&
65+
touch test.txt/test.txt &&
66+
git checkout . &&
67+
test -z "$(git status -s)" &&
68+
echo A > expect.txt &&
69+
test_cmp expect.txt test.txt &&
70+
cd .. &&
71+
rm -rf fscache-test
72+
'
73+
3874
test_expect_success setup '
3975
fill x y z >same &&
4076
fill 1 2 3 4 5 6 7 8 >one &&

0 commit comments

Comments
 (0)