mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
The previous three changes contributed performance improvements to 'git apply', 'git add -p', and 'git reset -p' when using a sparse index. The improvement to 'git apply' also improved 'git checkout -p'. Add performance tests to demonstrate this (and to help validate that performance remains good in the future). In the truncated test output below, we see that the full checkout performance changes within noise expectations, but the sparse index cases improve 33% and then 96% for 'git add -p' and 41% and then 95% for 'git reset -p'. 'git checkout -p' improves immediatley by 91% because it does not need any change to its builtin. Test HEAD~4 HEAD~3 HEAD~2 HEAD~1 ------------------------------------------------------------------------------------- 2000.118: ... git add -p (full-v3) 0.79 0.79 +0.0% 0.82 +3.8% 0.82 +3.8% 2000.119: ... git add -p (full-v4) 0.74 0.76 +2.7% 0.74 +0.0% 0.76 +2.7% 2000.120: ... git add -p (sparse-v3) 1.94 1.28 -34.0% 0.07 -96.4% 0.07 -96.4% 2000.121: ... git add -p (sparse-v4) 1.93 1.28 -33.7% 0.06 -96.9% 0.06 -96.9% 2000.122: ... git checkout -p (full-v3) 1.18 1.18 +0.0% 1.18 +0.0% 1.19 +0.8% 2000.123: ... git checkout -p (full-v4) 1.10 1.12 +1.8% 1.11 +0.9% 1.11 +0.9% 2000.124: ... git checkout -p (sparse-v3) 1.31 0.11 -91.6% 0.11 -91.6% 0.11 -91.6% 2000.125: ... git checkout -p (sparse-v4) 1.29 0.11 -91.5% 0.11 -91.5% 0.11 -91.5% 2000.126: ... git reset -p (full-v3) 0.81 0.80 -1.2% 0.83 +2.5% 0.83 +2.5% 2000.127: ... git reset -p (full-v4) 0.78 0.77 -1.3% 0.77 -1.3% 0.78 +0.0% 2000.128: ... git reset -p (sparse-v3) 1.58 0.92 -41.8% 0.91 -42.4% 0.07 -95.6% 2000.129: ... git reset -p (sparse-v4) 1.58 0.92 -41.8% 0.92 -41.8% 0.07 -95.6% It is worth noting that if our test was more involved and had multiple hunks to evaluate, then the time spent in 'git apply' would dominate due to multiple index loads and writes. As it stands, we need the sparse index improvement in 'git add -p' itself to confirm this performance improvement. Since the change for 'git add -i' is identical, we avoid a second test case for that similar operation. Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
143 lines
4.2 KiB
Bash
Executable File
143 lines
4.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description="test performance of Git operations using the index"
|
|
|
|
. ./perf-lib.sh
|
|
|
|
test_perf_default_repo
|
|
|
|
SPARSE_CONE=f2/f4
|
|
|
|
test_expect_success 'setup repo and indexes' '
|
|
git reset --hard HEAD &&
|
|
|
|
# Remove submodules from the example repo, because our
|
|
# duplication of the entire repo creates an unlikely data shape.
|
|
if git config --file .gitmodules --get-regexp "submodule.*.path" >modules
|
|
then
|
|
git rm $(awk "{print \$2}" modules) &&
|
|
git commit -m "remove submodules" || return 1
|
|
fi &&
|
|
|
|
echo bogus >a &&
|
|
cp a b &&
|
|
git add a b &&
|
|
git commit -m "level 0" &&
|
|
BLOB=$(git rev-parse HEAD:a) &&
|
|
OLD_COMMIT=$(git rev-parse HEAD) &&
|
|
OLD_TREE=$(git rev-parse HEAD^{tree}) &&
|
|
|
|
for i in $(test_seq 1 3)
|
|
do
|
|
cat >in <<-EOF &&
|
|
100755 blob $BLOB a
|
|
040000 tree $OLD_TREE f1
|
|
040000 tree $OLD_TREE f2
|
|
040000 tree $OLD_TREE f3
|
|
040000 tree $OLD_TREE f4
|
|
EOF
|
|
NEW_TREE=$(git mktree <in) &&
|
|
NEW_COMMIT=$(git commit-tree $NEW_TREE -p $OLD_COMMIT -m "level $i") &&
|
|
OLD_TREE=$NEW_TREE &&
|
|
OLD_COMMIT=$NEW_COMMIT || return 1
|
|
done &&
|
|
|
|
git sparse-checkout init --cone &&
|
|
git tag -a v1.0 -m "Final" &&
|
|
git sparse-checkout set $SPARSE_CONE &&
|
|
git checkout -b wide $OLD_COMMIT &&
|
|
|
|
for l2 in f1 f2 f3 f4
|
|
do
|
|
echo more bogus >>$SPARSE_CONE/$l2/a &&
|
|
git commit -a -m "edit $SPARSE_CONE/$l2/a" || return 1
|
|
done &&
|
|
|
|
git -c core.sparseCheckoutCone=true clone --branch=wide --sparse . full-v3 &&
|
|
(
|
|
cd full-v3 &&
|
|
git sparse-checkout init --cone &&
|
|
git sparse-checkout set $SPARSE_CONE &&
|
|
git config index.version 3 &&
|
|
git update-index --index-version=3 &&
|
|
git checkout HEAD~4
|
|
) &&
|
|
git -c core.sparseCheckoutCone=true clone --branch=wide --sparse . full-v4 &&
|
|
(
|
|
cd full-v4 &&
|
|
git sparse-checkout init --cone &&
|
|
git sparse-checkout set $SPARSE_CONE &&
|
|
git config index.version 4 &&
|
|
git update-index --index-version=4 &&
|
|
git checkout HEAD~4
|
|
) &&
|
|
git -c core.sparseCheckoutCone=true clone --branch=wide --sparse . sparse-v3 &&
|
|
(
|
|
cd sparse-v3 &&
|
|
git sparse-checkout init --cone --sparse-index &&
|
|
git sparse-checkout set $SPARSE_CONE &&
|
|
git config index.version 3 &&
|
|
git update-index --index-version=3 &&
|
|
git checkout HEAD~4
|
|
) &&
|
|
git -c core.sparseCheckoutCone=true clone --branch=wide --sparse . sparse-v4 &&
|
|
(
|
|
cd sparse-v4 &&
|
|
git sparse-checkout init --cone --sparse-index &&
|
|
git sparse-checkout set $SPARSE_CONE &&
|
|
git config index.version 4 &&
|
|
git update-index --index-version=4 &&
|
|
git checkout HEAD~4
|
|
)
|
|
'
|
|
|
|
test_perf_on_all () {
|
|
command="$@"
|
|
for repo in full-v3 full-v4 \
|
|
sparse-v3 sparse-v4
|
|
do
|
|
test_perf "$command ($repo)" "
|
|
(
|
|
cd $repo &&
|
|
echo >>$SPARSE_CONE/a &&
|
|
$command
|
|
)
|
|
"
|
|
done
|
|
}
|
|
|
|
test_perf_on_all git status
|
|
test_perf_on_all 'git stash && git stash pop'
|
|
test_perf_on_all 'echo >>new && git stash -u && git stash pop'
|
|
test_perf_on_all git add -A
|
|
test_perf_on_all git add .
|
|
test_perf_on_all git commit -a -m A
|
|
test_perf_on_all git checkout -f -
|
|
test_perf_on_all "git sparse-checkout add f2/f3/f1 && git sparse-checkout set $SPARSE_CONE"
|
|
test_perf_on_all git reset
|
|
test_perf_on_all git reset --hard
|
|
test_perf_on_all git reset -- does-not-exist
|
|
test_perf_on_all git diff
|
|
test_perf_on_all git diff --cached
|
|
test_perf_on_all git blame $SPARSE_CONE/a
|
|
test_perf_on_all git blame $SPARSE_CONE/f3/a
|
|
test_perf_on_all git read-tree -mu HEAD
|
|
test_perf_on_all git checkout-index -f --all
|
|
test_perf_on_all git update-index --add --remove $SPARSE_CONE/a
|
|
test_perf_on_all "git rm -f $SPARSE_CONE/a && git checkout HEAD -- $SPARSE_CONE/a"
|
|
test_perf_on_all git grep --cached bogus -- "f2/f1/f1/*"
|
|
test_perf_on_all git write-tree
|
|
test_perf_on_all git describe --dirty
|
|
test_perf_on_all 'echo >>new && git describe --dirty'
|
|
test_perf_on_all git diff-files
|
|
test_perf_on_all git diff-files -- $SPARSE_CONE/a
|
|
test_perf_on_all git diff-tree HEAD
|
|
test_perf_on_all git diff-tree HEAD -- $SPARSE_CONE/a
|
|
test_perf_on_all "git worktree add ../temp && git worktree remove ../temp"
|
|
test_perf_on_all git check-attr -a -- $SPARSE_CONE/a
|
|
test_perf_on_all 'echo >>a && test_write_lines y | git add -p'
|
|
test_perf_on_all 'test_write_lines y y y | git checkout --patch -'
|
|
test_perf_on_all 'echo >>a && git add a && test_write_lines y | git reset --patch'
|
|
|
|
test_done
|