Skip to content

Commit 950a234

Browse files
jeffhostetlergitster
authored andcommitted
string-list: use ALLOC_GROW macro when reallocing string_list
Use ALLOC_GROW() macro when reallocing a string_list array rather than simply increasing it by 32. This is a performance optimization. During status on a very large repo and there are many changes, a significant percentage of the total run time is spent reallocing the wt_status.changes array. This change decreases the time in wt_status_collect_changes_worktree() from 125 seconds to 45 seconds on my very large repository. This produced a modest gain on my 1M file artificial repo, but broke even on linux.git. Test HEAD^^ HEAD --------------------------------------------------------------------------------------- 0005.2: read-tree status br_ballast (1000001) 8.29(5.62+2.62) 8.22(5.57+2.63) -0.8% Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3b9e3c2 commit 950a234

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

string-list.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ static int add_entry(int insert_at, struct string_list *list, const char *string
4141
if (exact_match)
4242
return -1 - index;
4343

44-
if (list->nr + 1 >= list->alloc) {
45-
list->alloc += 32;
46-
REALLOC_ARRAY(list->items, list->alloc);
47-
}
44+
ALLOC_GROW(list->items, list->nr+1, list->alloc);
4845
if (index < list->nr)
4946
memmove(list->items + index + 1, list->items + index,
5047
(list->nr - index)

t/perf/p0005-status.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/sh
2+
#
3+
# This test measures the performance of various read-tree
4+
# and status operations. It is primarily interested in
5+
# the algorithmic costs of index operations and recursive
6+
# tree traversal -- and NOT disk I/O on thousands of files.
7+
8+
test_description="Tests performance of read-tree"
9+
10+
. ./perf-lib.sh
11+
12+
test_perf_default_repo
13+
14+
# If the test repo was generated by ./repos/many-files.sh
15+
# then we know something about the data shape and branches,
16+
# so we can isolate testing to the ballast-related commits
17+
# and setup sparse-checkout so we don't have to populate
18+
# the ballast files and directories.
19+
#
20+
# Otherwise, we make some general assumptions about the
21+
# repo and consider the entire history of the current
22+
# branch to be the ballast.
23+
24+
test_expect_success "setup repo" '
25+
if git rev-parse --verify refs/heads/p0006-ballast^{commit}
26+
then
27+
echo Assuming synthetic repo from many-files.sh
28+
git branch br_base master
29+
git branch br_ballast p0006-ballast
30+
git config --local core.sparsecheckout 1
31+
cat >.git/info/sparse-checkout <<-EOF
32+
/*
33+
!ballast/*
34+
EOF
35+
else
36+
echo Assuming non-synthetic repo...
37+
git branch br_base $(git rev-list HEAD | tail -n 1)
38+
git branch br_ballast HEAD
39+
fi &&
40+
git checkout -q br_ballast &&
41+
nr_files=$(git ls-files | wc -l)
42+
'
43+
44+
test_perf "read-tree status br_ballast ($nr_files)" '
45+
git read-tree HEAD &&
46+
git status
47+
'
48+
49+
test_done

0 commit comments

Comments
 (0)