Skip to content

Commit 0e47bca

Browse files
vdyettaylorr
authored andcommitted
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 <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 68fcd48 commit 0e47bca

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

builtin/reset.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t
7373
case HARD:
7474
opts.update = 1;
7575
opts.reset = UNPACK_RESET_OVERWRITE_UNTRACKED;
76+
opts.skip_cache_tree_update = 1;
7677
break;
7778
case MIXED:
7879
opts.reset = UNPACK_RESET_PROTECT_UNTRACKED;
80+
opts.skip_cache_tree_update = 1;
7981
/* but opts.update=0, so working tree not updated */
8082
break;
8183
default:

t/perf/p7102-reset.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)