Skip to content

Commit 529a7c9

Browse files
committed
perf: add tests for tag --contains
These tests can demonstrate the changes in "tag --contains" speed over time. The interesting points in history are: - pre-ffc4b80, where we used a series of N merge-base traversals - ffc4b80 up to the current master, where we moved to a single depth-first traversal - the previous commit, where we moved from depth-first to a multi-tip merge-base The interesting cases to measure are: - checking which tags contain a recent commit (we use HEAD~100 here) - checking which tags contain a very ancient commit (we use the last commit output by rev-list) - checking which tags contain a commit in the middle (we use HEAD~5000, which goes back 5 years in git.git) - all of the above, but instead of looking at all commits, considering only recent ones (we pick the most recent tag by its tagger date) Here are the timings for git.git: Test ffc4b80^ origin/master HEAD ----------------------------------------------------------------------------------------------------- 7100.3: contains recent/all 3.53(3.51+0.00) 0.33(0.31+0.01) -90.7% 0.35(0.33+0.02) -90.1% 7100.4: contains recent/v2.12.0 0.09(0.08+0.00) 0.33(0.32+0.00) +266.7% 0.08(0.08+0.00) -11.1% 7100.5: contains old/all 2.11(2.10+0.00) 0.26(0.25+0.00) -87.7% 0.35(0.33+0.01) -83.4% 7100.6: contains old/v2.12.0 0.33(0.32+0.01) 0.25(0.24+0.00) -24.2% 0.33(0.32+0.00) +0.0% 7100.7: contains ancient/all 1.39(1.37+0.01) 0.16(0.15+0.00) -88.5% 0.35(0.34+0.00) -74.8% 7100.8: contains ancient/v2.12.0 0.34(0.32+0.01) 0.11(0.10+0.00) -67.6% 0.34(0.33+0.00) +0.0% You can see that ffc4b80 vastly improved the normal case of checking all tags. This is because we avoid walking over the same parts of history over and over. However, when looking only for a recent tag (v2.12.0 in these tests), it sometimes performs much worse than the original. This is not surprising. For a merge-base solution, we can quit when we hit history shared between the contained commit and the tag. For ffc4b80's depth-first approach, we typically go all the way to the roots before backtracking. For the ancient/v2.0.1 case, that's not a big deal, because the merge base requires us doing that anyway. But for recent/v2.0.1, the merge-base answer should involve only recent history. The new traversal code performs about as well as the depth-first code in the normal case, but fixes the regression in the recent/v2.0.1 case. Signed-off-by: Jeff King <peff@peff.net>
1 parent 0ed87cd commit 529a7c9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

t/perf/p7100-tag-contains.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
test_description='speed of tag --contains lookups'
4+
. ./perf-lib.sh
5+
6+
test_perf_default_repo
7+
8+
test_expect_success 'find reference points' '
9+
recent=$(git rev-list HEAD | head -500 | tail -n 1) &&
10+
old=$(git rev-list HEAD | head -15000 | tail -n 1) &&
11+
ancient=$(git rev-list HEAD | tail -n 1)
12+
'
13+
14+
test_expect_success 'find most recent tag' '
15+
tag=$(git for-each-ref --sort=-taggerdate \
16+
--format="%(refname:short)" \
17+
refs/tags |
18+
head -n 1)
19+
'
20+
21+
for distance in recent old ancient; do
22+
contains=$(eval echo \$$distance)
23+
for match in "" "$tag"; do
24+
test_perf "contains $distance/${match:-all}" "
25+
git tag -l --contains $contains $match
26+
"
27+
done
28+
done
29+
30+
test_done

0 commit comments

Comments
 (0)