mirror of
https://github.com/git-for-windows/git.git
synced 2026-06-13 00:50:13 -05:00
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>
This commit is contained in:
committed by
Johannes Schindelin
parent
b2c8d16d2f
commit
2bdea0514f
@@ -407,6 +407,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
|
|||||||
if (pc_workers > 1)
|
if (pc_workers > 1)
|
||||||
init_parallel_checkout();
|
init_parallel_checkout();
|
||||||
|
|
||||||
|
enable_fscache(1);
|
||||||
for (pos = 0; pos < the_repository->index->cache_nr; pos++) {
|
for (pos = 0; pos < the_repository->index->cache_nr; pos++) {
|
||||||
struct cache_entry *ce = the_repository->index->cache[pos];
|
struct cache_entry *ce = the_repository->index->cache[pos];
|
||||||
if (ce->ce_flags & CE_MATCHED) {
|
if (ce->ce_flags & CE_MATCHED) {
|
||||||
@@ -432,6 +433,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
|
|||||||
errs |= run_parallel_checkout(&state, pc_workers, pc_threshold,
|
errs |= run_parallel_checkout(&state, pc_workers, pc_threshold,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
mem_pool_discard(&ce_mem_pool, should_validate_cache_entries());
|
mem_pool_discard(&ce_mem_pool, should_validate_cache_entries());
|
||||||
|
enable_fscache(0);
|
||||||
remove_marked_cache_entries(the_repository->index, 1);
|
remove_marked_cache_entries(the_repository->index, 1);
|
||||||
remove_scheduled_dirs();
|
remove_scheduled_dirs();
|
||||||
errs |= finish_delayed_checkout(&state, opts->show_progress);
|
errs |= finish_delayed_checkout(&state, opts->show_progress);
|
||||||
|
|||||||
@@ -428,6 +428,18 @@ int fscache_enable(int enable)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Flush cached stats result when fscache is enabled.
|
||||||
|
*/
|
||||||
|
void fscache_flush(void)
|
||||||
|
{
|
||||||
|
if (enabled) {
|
||||||
|
EnterCriticalSection(&mutex);
|
||||||
|
fscache_clear();
|
||||||
|
LeaveCriticalSection(&mutex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Lstat replacement, uses the cache if enabled, otherwise redirects to
|
* Lstat replacement, uses the cache if enabled, otherwise redirects to
|
||||||
* mingw_lstat.
|
* mingw_lstat.
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ int fscache_enable(int enable);
|
|||||||
int fscache_enabled(const char *path);
|
int fscache_enabled(const char *path);
|
||||||
#define is_fscache_enabled(path) fscache_enabled(path)
|
#define is_fscache_enabled(path) fscache_enabled(path)
|
||||||
|
|
||||||
|
void fscache_flush(void);
|
||||||
|
#define flush_fscache() fscache_flush()
|
||||||
|
|
||||||
DIR *fscache_opendir(const char *dir);
|
DIR *fscache_opendir(const char *dir);
|
||||||
int fscache_lstat(const char *file_name, struct stat *buf);
|
int fscache_lstat(const char *file_name, struct stat *buf);
|
||||||
|
|
||||||
|
|||||||
3
entry.c
3
entry.c
@@ -409,6 +409,9 @@ static int write_entry(struct cache_entry *ce, char *path, struct conv_attrs *ca
|
|||||||
}
|
}
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
|
/* Flush cached lstat in fscache after writing to disk. */
|
||||||
|
flush_fscache();
|
||||||
|
|
||||||
if (state->refresh_cache) {
|
if (state->refresh_cache) {
|
||||||
if (!fstat_done && lstat(ce->name, &st) < 0)
|
if (!fstat_done && lstat(ce->name, &st) < 0)
|
||||||
return error_errno("unable to stat just-written file %s",
|
return error_errno("unable to stat just-written file %s",
|
||||||
|
|||||||
@@ -1576,6 +1576,10 @@ static inline int is_missing_file_error(int errno_)
|
|||||||
#define is_fscache_enabled(path) (0)
|
#define is_fscache_enabled(path) (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef flush_fscache
|
||||||
|
#define flush_fscache() /* noop */
|
||||||
|
#endif
|
||||||
|
|
||||||
int cmd_main(int, const char **);
|
int cmd_main(int, const char **);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -639,6 +639,7 @@ static void write_items_sequentially(struct checkout *state)
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
flush_fscache();
|
||||||
for (i = 0; i < parallel_checkout.nr; i++) {
|
for (i = 0; i < parallel_checkout.nr; i++) {
|
||||||
struct parallel_checkout_item *pc_item = ¶llel_checkout.items[i];
|
struct parallel_checkout_item *pc_item = ¶llel_checkout.items[i];
|
||||||
write_pc_item(pc_item, state);
|
write_pc_item(pc_item, state);
|
||||||
|
|||||||
@@ -35,6 +35,42 @@ fill () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
test_expect_success MINGW 'fscache flush cache' '
|
||||||
|
|
||||||
|
git init fscache-test &&
|
||||||
|
cd fscache-test &&
|
||||||
|
git config core.fscache 1 &&
|
||||||
|
echo A > test.txt &&
|
||||||
|
git add test.txt &&
|
||||||
|
git commit -m A &&
|
||||||
|
echo B >> test.txt &&
|
||||||
|
git checkout . &&
|
||||||
|
test -z "$(git status -s)" &&
|
||||||
|
echo A > expect.txt &&
|
||||||
|
test_cmp expect.txt test.txt &&
|
||||||
|
cd .. &&
|
||||||
|
rm -rf fscache-test
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success MINGW 'fscache flush cache dir' '
|
||||||
|
|
||||||
|
git init fscache-test &&
|
||||||
|
cd fscache-test &&
|
||||||
|
git config core.fscache 1 &&
|
||||||
|
echo A > test.txt &&
|
||||||
|
git add test.txt &&
|
||||||
|
git commit -m A &&
|
||||||
|
rm test.txt &&
|
||||||
|
mkdir test.txt &&
|
||||||
|
touch test.txt/test.txt &&
|
||||||
|
git checkout . &&
|
||||||
|
test -z "$(git status -s)" &&
|
||||||
|
echo A > expect.txt &&
|
||||||
|
test_cmp expect.txt test.txt &&
|
||||||
|
cd .. &&
|
||||||
|
rm -rf fscache-test
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success setup '
|
test_expect_success setup '
|
||||||
fill x y z >same &&
|
fill x y z >same &&
|
||||||
fill 1 2 3 4 5 6 7 8 >one &&
|
fill 1 2 3 4 5 6 7 8 >one &&
|
||||||
|
|||||||
Reference in New Issue
Block a user