Skip to content

Commit 71cc0bd

Browse files
author
Takuto Ikuta
committed
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 <tikuta@chromium.org>
1 parent 1a4ee4d commit 71cc0bd

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

builtin/checkout.c

+2
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ static int checkout_paths(const struct checkout_opts *opts,
359359
state.istate = &the_index;
360360

361361
enable_delayed_checkout(&state);
362+
enable_fscache(1);
362363
for (pos = 0; pos < active_nr; pos++) {
363364
struct cache_entry *ce = active_cache[pos];
364365
if (ce->ce_flags & CE_MATCHED) {
@@ -373,6 +374,7 @@ static int checkout_paths(const struct checkout_opts *opts,
373374
pos = skip_same_name(ce, pos) - 1;
374375
}
375376
}
377+
enable_fscache(0);
376378
errs |= finish_delayed_checkout(&state);
377379

378380
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))

compat/win32/fscache.c

+12
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,18 @@ int fscache_enable(int enable)
411411
return result;
412412
}
413413

414+
/*
415+
* Flush cached stats result when fscache is enabled.
416+
*/
417+
void fscache_flush()
418+
{
419+
if (enabled) {
420+
EnterCriticalSection(&mutex);
421+
fscache_clear();
422+
LeaveCriticalSection(&mutex);
423+
}
424+
}
425+
414426
/*
415427
* Lstat replacement, uses the cache if enabled, otherwise redirects to
416428
* 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();
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
@@ -366,6 +366,9 @@ static int write_entry(struct cache_entry *ce,
366366
}
367367

368368
finish:
369+
// Flush cached lstat in fscache after writing disk.
370+
flush_fscache();
371+
369372
if (state->refresh_cache) {
370373
assert(state->istate);
371374
if (!fstat_done)

git-compat-util.h

+4
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,10 @@ static inline int is_missing_file_error(int errno_)
12821282
#define is_fscache_enabled(path) (0)
12831283
#endif
12841284

1285+
#ifndef flush_fscache
1286+
#define flush_fscache() /* noop */
1287+
#endif
1288+
12851289
extern int cmd_main(int, const char **);
12861290

12871291
/*

t/t7201-co.sh

+36
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,42 @@ fill () {
3232
}
3333

3434

35+
test_expect_success MINGW 'fscache flush cache' '
36+
37+
git init fscache-test &&
38+
cd fscache-test &&
39+
git config core.fscache 1 &&
40+
echo A > test.txt &&
41+
git add test.txt &&
42+
git commit -m A &&
43+
echo B >> test.txt &&
44+
git checkout . &&
45+
test -z "$(git status -s)" &&
46+
echo A > expect.txt &&
47+
test_cmp expect.txt test.txt &&
48+
cd .. &&
49+
rm -rf fscache-test
50+
'
51+
52+
test_expect_success MINGW 'fscache flush cache dir' '
53+
54+
git init fscache-test &&
55+
cd fscache-test &&
56+
git config core.fscache 1 &&
57+
echo A > test.txt &&
58+
git add test.txt &&
59+
git commit -m A &&
60+
rm test.txt &&
61+
mkdir test.txt &&
62+
touch test.txt/test.txt &&
63+
git checkout . &&
64+
test -z "$(git status -s)" &&
65+
echo A > expect.txt &&
66+
test_cmp expect.txt test.txt &&
67+
cd .. &&
68+
rm -rf fscache-test
69+
'
70+
3571
test_expect_success setup '
3672
3773
fill x y z > same &&

0 commit comments

Comments
 (0)