Skip to content

Commit 00ec50e

Browse files
benpeartgitster
authored andcommitted
read_index_from(): speed index loading by skipping verification of the entry order
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fc849d8 commit 00ec50e

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

builtin/fsck.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
763763

764764
if (keep_cache_objects) {
765765
verify_index_checksum = 1;
766+
verify_ce_order = 1;
766767
read_cache();
767768
for (i = 0; i < active_nr; i++) {
768769
unsigned int mode;

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ extern int hold_locked_index(struct lock_file *, int);
720720
extern void set_alternate_index_output(const char *);
721721

722722
extern int verify_index_checksum;
723+
extern int verify_ce_order;
723724

724725
/* Environment bits from configuration mechanism */
725726
extern int trust_executable_bit;

read-cache.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,9 @@ struct ondisk_cache_entry_extended {
15091509
/* Allow fsck to force verification of the index checksum. */
15101510
int verify_index_checksum;
15111511

1512+
/* Allow fsck to force verification of the cache entry order. */
1513+
int verify_ce_order;
1514+
15121515
static int verify_hdr(struct cache_header *hdr, unsigned long size)
15131516
{
15141517
git_SHA_CTX c;
@@ -1666,6 +1669,9 @@ static void check_ce_order(struct index_state *istate)
16661669
{
16671670
unsigned int i;
16681671

1672+
if (!verify_ce_order)
1673+
return;
1674+
16691675
for (i = 1; i < istate->cache_nr; i++) {
16701676
struct cache_entry *ce = istate->cache[i - 1];
16711677
struct cache_entry *next_ce = istate->cache[i];

0 commit comments

Comments
 (0)