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 <benpeart@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ben Peart committed Oct 18, 2017 at 10:27 UTC 00ec50e56d136de41f43c33f39cdbee83f3e4458
3 files changed +8
builtin/fsck.c
+1
@@ -763,6 +763,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
763
764 if (keep_cache_objects) {
765 verify_index_checksum = 1;
766 + verify_ce_order = 1;
767 read_cache();
768 for (i = 0; i < active_nr; i++) {
769 unsigned int mode;
cache.h
+1
@@ -720,6 +720,7 @@ extern int hold_locked_index(struct lock_file *, int);
720 extern void set_alternate_index_output(const char *);
721
722 extern int verify_index_checksum;
723 +extern int verify_ce_order;
724
725 /* Environment bits from configuration mechanism */
726 extern int trust_executable_bit;
read-cache.c
+6
@@ -1509,6 +1509,9 @@ struct ondisk_cache_entry_extended {
1509 /* Allow fsck to force verification of the index checksum. */
1510 int verify_index_checksum;
1511
1512 +/* Allow fsck to force verification of the cache entry order. */
1513 +int verify_ce_order;
1514 +
1515 static int verify_hdr(struct cache_header *hdr, unsigned long size)
1516 {
1517 git_SHA_CTX c;
@@ -1666,6 +1669,9 @@ static void check_ce_order(struct index_state *istate)
1669 {
1670 unsigned int i;
1671
1672 + if (!verify_ce_order)
1673 + return;
1674 +
1675 for (i = 1; i < istate->cache_nr; i++) {
1676 struct cache_entry *ce = istate->cache[i - 1];
1677 struct cache_entry *next_ce = istate->cache[i];