Skip to content

Commit 8466efa

Browse files
malon7782gitster
authored andcommitted
t/perf/p3400: speed up setup using fast-import
The setup phase in 't/perf/p3400-rebase.sh' generates 100 commits to simulate a noisy history. It currently uses a shell loop that invokes 'git add', 'git commit', 'test_seq', and 'sort' in each iteration. This incurs significant overhead due to repeated process spawning. Optimize the setup by using 'git fast-import' to generate the commit history. Additionally, pre-compute the forward and reversed file contents to avoid repetitive execution of 'seq' and 'sort'. To ensure the test measures rebase performance against a consistent object layout (rather than the suboptimal pack/loose objects created by the raw import), perform a full repack (`git repack -a -d`) at the end of the setup. This reduces the setup time significantly while maintaining the validity of the subsequent performance tests. Performance enhancement (Average value of 5 tests): Real Rebase Before: 29.045s 13.34s After: 21.989s 12.84s Measured on Lenovo Yoga 2020, Ubuntu 24.04. Signed-off-by: Tian Yuchen <a3205153416@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ea71764 commit 8466efa

1 file changed

Lines changed: 38 additions & 15 deletions

File tree

t/perf/p3400-rebase.sh

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,44 @@ test_expect_success 'setup rebasing on top of a lot of changes' '
99
git checkout -f -B base &&
1010
git checkout -B to-rebase &&
1111
git checkout -B upstream &&
12-
for i in $(test_seq 100)
13-
do
14-
# simulate huge diffs
15-
echo change$i >unrelated-file$i &&
16-
test_seq 1000 >>unrelated-file$i &&
17-
git add unrelated-file$i &&
18-
test_tick &&
19-
git commit -m commit$i unrelated-file$i &&
20-
echo change$i >unrelated-file$i &&
21-
test_seq 1000 | sort -nr >>unrelated-file$i &&
22-
git add unrelated-file$i &&
23-
test_tick &&
24-
git commit -m commit$i-reverse unrelated-file$i ||
25-
return 1
26-
done &&
12+
test_seq 1000 >content_fwd &&
13+
sort -nr content_fwd >content_rev &&
14+
(
15+
for i in $(test_seq 100)
16+
do
17+
test_tick &&
18+
echo "commit refs/heads/upstream" &&
19+
echo "committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE" &&
20+
echo "data <<EOF" &&
21+
echo "commit$i" &&
22+
echo "EOF" &&
23+
24+
if test "$i" = 1; then
25+
echo "from refs/heads/upstream^0"
26+
fi &&
27+
28+
echo "M 100644 inline unrelated-file$i" &&
29+
echo "data <<EOF" &&
30+
echo "change$i" &&
31+
cat content_fwd &&
32+
echo "EOF" &&
33+
34+
echo "commit refs/heads/upstream" &&
35+
echo "committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE" &&
36+
echo "data <<EOF" &&
37+
echo "commit$i-reverse" &&
38+
echo "EOF" &&
39+
echo "M 100644 inline unrelated-file$i" &&
40+
echo "data <<EOF" &&
41+
echo "change$i" &&
42+
cat content_rev &&
43+
echo "EOF" || exit 1
44+
done
45+
) >fast_import_stream &&
46+
47+
git fast-import <fast_import_stream &&
48+
git repack -a -d &&
49+
git checkout -f upstream &&
2750
git checkout to-rebase &&
2851
test_commit our-patch interesting-file
2952
'

0 commit comments

Comments
 (0)