Skip to content

Commit

Permalink
speed up refresh_index() by utilizing preload_index()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
benpeart authored and gitster committed Oct 30, 2018
1 parent c670b1f commit 99ce720
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,9 @@ extern int daemonize(void);
/* Initialize and use the cache information */
struct lock_file;
extern int read_index(struct index_state *);
extern void preload_index(struct index_state *index,
const struct pathspec *pathspec,
unsigned int refresh_flags);
extern int read_index_preload(struct index_state *,
const struct pathspec *pathspec,
unsigned int refresh_flags);
Expand Down
8 changes: 4 additions & 4 deletions preload-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "progress.h"

#ifdef NO_PTHREADS
static void preload_index(struct index_state *index,
void preload_index(struct index_state *index,
const struct pathspec *pathspec,
unsigned int refresh_flags)
{
Expand Down Expand Up @@ -100,9 +100,9 @@ static void *preload_thread(void *_data)
return NULL;
}

static void preload_index(struct index_state *index,
const struct pathspec *pathspec,
unsigned int refresh_flags)
void preload_index(struct index_state *index,
const struct pathspec *pathspec,
unsigned int refresh_flags)
{
int threads, i, work, offset;
struct thread_data data[MAX_PARALLEL];
Expand Down
6 changes: 6 additions & 0 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,12 @@ int refresh_index(struct index_state *istate, unsigned int flags,
typechange_fmt = (in_porcelain ? "T\t%s\n" : "%s needs update\n");
added_fmt = (in_porcelain ? "A\t%s\n" : "%s needs update\n");
unmerged_fmt = (in_porcelain ? "U\t%s\n" : "%s: needs merge\n");
/*
* Use the multi-threaded preload_index() to refresh most of the
* cache entries quickly then in the single threaded loop below,
* we only have to do the special cases that are left.
*/
preload_index(istate, pathspec, 0);
for (i = 0; i < istate->cache_nr; i++) {
struct cache_entry *ce, *new_entry;
int cache_errno = 0;
Expand Down

0 comments on commit 99ce720

Please sign in to comment.