Skip to content

Commit 99ce720

Browse files
benpeartgitster
authored andcommitted
speed up refresh_index() by utilizing preload_index()
Speed up refresh_index() by utilizing preload_index() to do most of the work spread across multiple threads. This works because most cache entries will get marked CE_UPTODATE so that refresh_cache_ent() can bail out early when called from within refresh_index(). On a Windows repo with ~200K files, this drops refresh times from 6.64 seconds to 2.87 seconds for a savings of 57%. Signed-off-by: Ben Peart <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c670b1f commit 99ce720

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

cache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,9 @@ extern int daemonize(void);
659659
/* Initialize and use the cache information */
660660
struct lock_file;
661661
extern int read_index(struct index_state *);
662+
extern void preload_index(struct index_state *index,
663+
const struct pathspec *pathspec,
664+
unsigned int refresh_flags);
662665
extern int read_index_preload(struct index_state *,
663666
const struct pathspec *pathspec,
664667
unsigned int refresh_flags);

preload-index.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "progress.h"
1010

1111
#ifdef NO_PTHREADS
12-
static void preload_index(struct index_state *index,
12+
void preload_index(struct index_state *index,
1313
const struct pathspec *pathspec,
1414
unsigned int refresh_flags)
1515
{
@@ -100,9 +100,9 @@ static void *preload_thread(void *_data)
100100
return NULL;
101101
}
102102

103-
static void preload_index(struct index_state *index,
104-
const struct pathspec *pathspec,
105-
unsigned int refresh_flags)
103+
void preload_index(struct index_state *index,
104+
const struct pathspec *pathspec,
105+
unsigned int refresh_flags)
106106
{
107107
int threads, i, work, offset;
108108
struct thread_data data[MAX_PARALLEL];

read-cache.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,12 @@ 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+
/*
1500+
* Use the multi-threaded preload_index() to refresh most of the
1501+
* cache entries quickly then in the single threaded loop below,
1502+
* we only have to do the special cases that are left.
1503+
*/
1504+
preload_index(istate, pathspec, 0);
14991505
for (i = 0; i < istate->cache_nr; i++) {
15001506
struct cache_entry *ce, *new_entry;
15011507
int cache_errno = 0;

0 commit comments

Comments
 (0)