Skip to content

Commit

Permalink
read_index_from(): Skip verification of the cache entry order to spee…
Browse files Browse the repository at this point in the history
…d index loading

There is code in post_read_index_from() to catch out of order entries
when reading an index file.  This order verification is ~13% of the cost
of every call to read_index_from().

Update check_ce_order() so that it skips this verification unless the
"verify_ce_order" global variable is set.

Teach fsck to force this verification.

The effect can be seen using t/perf/p0002-read-cache.sh:

Test                                          HEAD              HEAD~1
--------------------------------------------------------------------------------------
0002.1: read_cache/discard_cache 1000 times   0.41(0.04+0.04)   0.50(0.00+0.10) +22.0%

Signed-off-by: Ben Peart <benpeart@microsoft.com>
  • Loading branch information
benpeart authored and dscho committed Nov 2, 2017
1 parent 26e4198 commit 4254e31
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions builtin/fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)

if (keep_cache_objects) {
verify_index_checksum = 1;
verify_ce_order = 1;
read_cache();
for (i = 0; i < active_nr; i++) {
unsigned int mode;
Expand Down
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ extern int hold_locked_index(struct lock_file *, int);
extern void set_alternate_index_output(const char *);

extern int verify_index_checksum;
extern int verify_ce_order;

/* Environment bits from configuration mechanism */
extern int trust_executable_bit;
Expand Down
6 changes: 6 additions & 0 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,9 @@ struct ondisk_cache_entry_extended {
/* Allow fsck to force verification of the index checksum. */
int verify_index_checksum;

/* Allow fsck to force verification of the cache entry order. */
int verify_ce_order;

static int verify_hdr(struct cache_header *hdr, unsigned long size)
{
git_SHA_CTX c;
Expand Down Expand Up @@ -1704,6 +1707,9 @@ static void check_ce_order(struct index_state *istate)
{
unsigned int i;

if (!verify_ce_order)
return;

for (i = 1; i < istate->cache_nr; i++) {
struct cache_entry *ce = istate->cache[i - 1];
struct cache_entry *next_ce = istate->cache[i];
Expand Down

0 comments on commit 4254e31

Please sign in to comment.