reset: use 'skip_cache_tree_update' option
Enable the 'skip_cache_tree_update' option in the variants that call 'prime_cache_tree()' after 'unpack_trees()' (specifically, 'git reset --mixed' and 'git reset --hard'). This avoids redundantly rebuilding the cache tree in both 'cache_tree_update()' at the end of 'unpack_trees()' and in 'prime_cache_tree()', resulting in a small (but consistent) performance improvement. From the newly-added 'p7102-reset.sh' test: Test before after -------------------------------------------------------------------- 7102.1: reset --hard (...) 2.11(0.40+1.54) 1.97(0.38+1.47) -6.6% Signed-off-by: Victoria Dye <vdye@github.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>
Victoria Dye committed
Nov 10, 2022 at 19:06 UTC
0e47bca0f7592f8053ffcc530d8afa1d2e364563
2 files changed
+23
builtin/reset.c
+2
@@ -73,9 +73,11 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t
73
case HARD:
74
opts.update = 1;
75
opts.reset = UNPACK_RESET_OVERWRITE_UNTRACKED;
76
+ opts.skip_cache_tree_update = 1;
77
break;
78
case MIXED:
79
opts.reset = UNPACK_RESET_PROTECT_UNTRACKED;
80
+ opts.skip_cache_tree_update = 1;
81
/* but opts.update=0, so working tree not updated */
82
break;
83
default:
t/perf/p7102-reset.sh
new
+21
@@ -0,0 +1,21 @@
1
+#!/bin/sh
2
+
3
+test_description='performance of reset'
4
+. ./perf-lib.sh
5
+
6
+test_perf_default_repo
7
+test_checkout_worktree
8
+
9
+test_perf 'reset --hard with change in tree' '
10
+ base=$(git rev-parse HEAD) &&
11
+ test_commit --no-tag A &&
12
+ new=$(git rev-parse HEAD) &&
13
+
14
+ for i in $(test_seq 10)
15
+ do
16
+ git reset --hard $new &&
17
+ git reset --hard $base || return $?
18
+ done
19
+'
20
+
21
+test_done