Skip to content

Commit f202666

Browse files
Takuto Ikutamjcheetham
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 6b57266 commit f202666

File tree

7 files changed

+61
-0
lines changed

7 files changed

+61
-0
lines changed

builtin/checkout.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
403403
if (pc_workers > 1)
404404
init_parallel_checkout();
405405

406+
enable_fscache(1);
406407
for (pos = 0; pos < the_repository->index->cache_nr; pos++) {
407408
struct cache_entry *ce = the_repository->index->cache[pos];
408409
if (ce->ce_flags & CE_MATCHED) {
@@ -428,6 +429,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
428429
errs |= run_parallel_checkout(&state, pc_workers, pc_threshold,
429430
NULL, NULL);
430431
mem_pool_discard(&ce_mem_pool, should_validate_cache_entries());
432+
enable_fscache(0);
431433
remove_marked_cache_entries(the_repository->index, 1);
432434
remove_scheduled_dirs();
433435
errs |= finish_delayed_checkout(&state, opts->show_progress);

compat/win32/fscache.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,18 @@ int fscache_enable(int enable)
428428
return result;
429429
}
430430

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

compat/win32/fscache.h

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ static int write_entry(struct cache_entry *ce, char *path, struct conv_attrs *ca
407407
}
408408

409409
finish:
410+
/* Flush cached lstat in fscache after writing to disk. */
411+
flush_fscache();
412+
410413
if (state->refresh_cache) {
411414
if (!fstat_done && lstat(ce->name, &st) < 0)
412415
return error_errno("unable to stat just-written file %s",

git-compat-util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,10 @@ static inline int is_missing_file_error(int errno_)
15411541
#define is_fscache_enabled(path) (0)
15421542
#endif
15431543

1544+
#ifndef flush_fscache
1545+
#define flush_fscache() /* noop */
1546+
#endif
1547+
15441548
int cmd_main(int, const char **);
15451549

15461550
/*

parallel-checkout.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ static void write_items_sequentially(struct checkout *state)
636636
{
637637
size_t i;
638638

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

t/t7201-co.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,42 @@ fill () {
3636
}
3737

3838

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

0 commit comments

Comments
 (0)