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 <benpeart@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ben Peart committed
Oct 29, 2018 at 16:41 UTC
99ce720c338ebeb37331bd98f724569837c74d0d
3 files changed
+13
-4
cache.h
+3
@@ -659,6 +659,9 @@ extern int daemonize(void);
659
/* Initialize and use the cache information */
660
struct lock_file;
661
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);
665
extern int read_index_preload(struct index_state *,
666
const struct pathspec *pathspec,
667
unsigned int refresh_flags);
preload-index.c
+4
-4
@@ -9,7 +9,7 @@
9
#include "progress.h"
10
11
#ifdef NO_PTHREADS
12
-static void preload_index(struct index_state *index,
12
+void preload_index(struct index_state *index,
13
const struct pathspec *pathspec,
14
unsigned int refresh_flags)
15
{
@@ -100,9 +100,9 @@ static void *preload_thread(void *_data)
100
return NULL;
101
}
102
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)
106
{
107
int threads, i, work, offset;
108
struct thread_data data[MAX_PARALLEL];
read-cache.c
+6
@@ -1496,6 +1496,12 @@ int refresh_index(struct index_state *istate, unsigned int flags,
1496
typechange_fmt = (in_porcelain ? "T\t%s\n" : "%s needs update\n");
1497
added_fmt = (in_porcelain ? "A\t%s\n" : "%s needs update\n");
1498
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);
1505
for (i = 0; i < istate->cache_nr; i++) {
1506
struct cache_entry *ce, *new_entry;
1507
int cache_errno = 0;