mirror of
https://github.com/git/git
synced 2024-10-29 17:08:46 +00:00
7cae7627c4
Turn on sparse index and remove ensure_full_index(). Before this patch, `git-grep` utilizes the ensure_full_index() method to expand the index and search all the entries. Because this method requires walking all the trees and constructing the index, it is the slow part within the whole command. To achieve better performance, this patch uses grep_tree() to search the sparse directory entries and get rid of the ensure_full_index() method. Why grep_tree() is a better choice over ensure_full_index()? 1) grep_tree() is as correct as ensure_full_index(). grep_tree() looks into every sparse-directory entry (represented by a tree) recursively when looping over the index, and the result of doing so matches the result of expanding the index. 2) grep_tree() utilizes pathspecs to limit the scope of searching. ensure_full_index() always expands the index, which means it will always walk all the trees and blobs in the repo without caring if the user only wants a subset of the content, i.e. using a pathspec. On the other hand, grep_tree() will only search the contents that match the pathspec, and thus possibly walking fewer trees. 3) grep_tree() does not construct and copy back a new index, while ensure_full_index() does. This also saves some time. ---------------- Performance test - Summary: p2000 tests demonstrate a ~71% execution time reduction for `git grep --cached bogus -- "f2/f1/f1/*"` using tree-walking logic. However, notice that this result varies depending on the pathspec given. See below "Command used for testing" for more details. Test HEAD~ HEAD ------------------------------------------------------- 2000.78: git grep ... (full-v3) 0.35 0.39 (≈) 2000.79: git grep ... (full-v4) 0.36 0.30 (≈) 2000.80: git grep ... (sparse-v3) 0.88 0.23 (-73.8%) 2000.81: git grep ... (sparse-v4) 0.83 0.26 (-68.6%) - Command used for testing: git grep --cached bogus -- "f2/f1/f1/*" The reason for specifying a pathspec is that, if we don't specify a pathspec, then grep_tree() will walk all the trees and blobs to find the pattern, and the time consumed doing so is not too different from using the original ensure_full_index() method, which also spends most of the time walking trees. However, when a pathspec is specified, this latest logic will only walk the area of trees enclosed by the pathspec, and the time consumed is reasonably a lot less. Generally speaking, because the performance gain is acheived by walking less trees, which are specified by the pathspec, the HEAD time v.s. HEAD~ time in sparse-v[3|4], should be proportional to "pathspec enclosed area" v.s. "all area", respectively. Namely, the wider the <pathspec> is encompassing, the less the performance difference between HEAD~ and HEAD, and vice versa. That is, if we don't specify a pathspec, the performance difference [1] is indistinguishable: both methods walk all the trees and take generally same amount of time (even with the index construction time included for ensure_full_index()). [1] Performance test result without pathspec (hence walking all trees): Command used: git grep --cached bogus Test HEAD~ HEAD --------------------------------------------------- 2000.78: git grep ... (full-v3) 6.17 5.19 (≈) 2000.79: git grep ... (full-v4) 6.19 5.46 (≈) 2000.80: git grep ... (sparse-v3) 6.57 6.44 (≈) 2000.81: git grep ... (sparse-v4) 6.65 6.28 (≈) -------------------------- NEEDSWORK about submodules There are a few NEEDSWORKs that belong to improvements beyond this topic. See the NEEDSWORK in builtin/grep.c::grep_submodule() for more context. The other two NEEDSWORKs in t1092 are also relative. Suggested-by: Derrick Stolee <derrickstolee@github.com> Helped-by: Derrick Stolee <derrickstolee@github.com> Helped-by: Victoria Dye <vdye@github.com> Helped-by: Elijah Newren <newren@gmail.com> Signed-off-by: Shaoxuan Yuan <shaoxuan.yuan02@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> |
||
---|---|---|
.. | ||
repos | ||
.gitignore | ||
aggregate.perl | ||
bisect_regression | ||
bisect_run_script | ||
config | ||
lib-bitmap.sh | ||
lib-pack.sh | ||
Makefile | ||
min_time.perl | ||
p0000-perf-lib-sanity.sh | ||
p0001-rev-list.sh | ||
p0002-read-cache.sh | ||
p0003-delta-base-cache.sh | ||
p0004-lazy-init-name-hash.sh | ||
p0005-status.sh | ||
p0006-read-tree-checkout.sh | ||
p0007-write-cache.sh | ||
p0008-odb-fsync.sh | ||
p0071-sort.sh | ||
p0100-globbing.sh | ||
p1006-cat-file.sh | ||
p1400-update-ref.sh | ||
p1450-fsck.sh | ||
p1451-fsck-skip-list.sh | ||
p2000-sparse-operations.sh | ||
p3400-rebase.sh | ||
p3404-rebase-interactive.sh | ||
p4000-diff-algorithms.sh | ||
p4001-diff-no-index.sh | ||
p4002-diff-color-moved.sh | ||
p4205-log-pretty-formats.sh | ||
p4209-pickaxe.sh | ||
p4211-line-log.sh | ||
p4220-log-grep-engines.sh | ||
p4221-log-grep-engines-fixed.sh | ||
p5302-pack-index.sh | ||
p5303-many-packs.sh | ||
p5304-prune.sh | ||
p5310-pack-bitmaps.sh | ||
p5311-pack-bitmaps-fetch.sh | ||
p5326-multi-pack-bitmaps.sh | ||
p5550-fetch-tags.sh | ||
p5551-fetch-rescan.sh | ||
p5600-partial-clone.sh | ||
p5601-clone-reference.sh | ||
p7000-filter-branch.sh | ||
p7300-clean.sh | ||
p7519-fsmonitor.sh | ||
p7527-builtin-fsmonitor.sh | ||
p7810-grep.sh | ||
p7820-grep-engines.sh | ||
p7821-grep-engines-fixed.sh | ||
p9300-fast-import-export.sh | ||
perf-lib.sh | ||
README | ||
run |
Git performance tests ===================== This directory holds performance testing scripts for git tools. The first part of this document describes the various ways in which you can run them. When fixing the tools or adding enhancements, you are strongly encouraged to add tests in this directory to cover what you are trying to fix or enhance. The later part of this short document describes how your test scripts should be organized. Running Tests ------------- The easiest way to run tests is to say "make". This runs all the tests on the current git repository. === Running 2 tests in this tree === [...] Test this tree --------------------------------------------------------- 0001.1: rev-list --all 0.54(0.51+0.02) 0001.2: rev-list --all --objects 6.14(5.99+0.11) 7810.1: grep worktree, cheap regex 0.16(0.16+0.35) 7810.2: grep worktree, expensive regex 7.90(29.75+0.37) 7810.3: grep --cached, cheap regex 3.07(3.02+0.25) 7810.4: grep --cached, expensive regex 9.39(30.57+0.24) Output format is in seconds "Elapsed(User + System)" You can compare multiple repositories and even git revisions with the 'run' script: $ ./run . origin/next /path/to/git-tree p0001-rev-list.sh where . stands for the current git tree. The full invocation is ./run [<revision|directory>...] [--] [<test-script>...] A '.' argument is implied if you do not pass any other revisions/directories. You can also manually test this or another git build tree, and then call the aggregation script to summarize the results: $ ./p0001-rev-list.sh [...] $ ./run /path/to/other/git -- ./p0001-rev-list.sh [...] $ ./aggregate.perl . /path/to/other/git ./p0001-rev-list.sh aggregate.perl has the same invocation as 'run', it just does not run anything beforehand. You can set the following variables (also in your config.mak): GIT_PERF_REPEAT_COUNT Number of times a test should be repeated for best-of-N measurements. Defaults to 3. GIT_PERF_MAKE_OPTS Options to use when automatically building a git tree for performance testing. E.g., -j6 would be useful. Passed directly to make as "make $GIT_PERF_MAKE_OPTS". GIT_PERF_MAKE_COMMAND An arbitrary command that'll be run in place of the make command, if set the GIT_PERF_MAKE_OPTS variable is ignored. Useful in cases where source tree changes might require issuing a different make command to different revisions. This can be (ab)used to monkeypatch or otherwise change the tree about to be built. Note that the build directory can be re-used for subsequent runs so the make command might get executed multiple times on the same tree, but don't count on any of that, that's an implementation detail that might change in the future. GIT_PERF_REPO GIT_PERF_LARGE_REPO Repositories to copy for the performance tests. The normal repo should be at least git.git size. The large repo should probably be about linux.git size for optimal results. Both default to the git.git you are running from. GIT_PERF_EXTRA Boolean to enable additional tests. Most test scripts are written to detect regressions between two versions of Git, and the output will compare timings for individual tests between those versions. Some scripts have additional tests which are not run by default, that show patterns within a single version of Git (e.g., performance of index-pack as the number of threads changes). These can be enabled with GIT_PERF_EXTRA. You can also pass the options taken by ordinary git tests; the most useful one is: --root=<directory>:: Create "trash" directories used to store all temporary data during testing under <directory>, instead of the t/ directory. Using this option with a RAM-based filesystem (such as tmpfs) can massively speed up the test suite. Naming Tests ------------ The performance test files are named as: pNNNN-commandname-details.sh where N is a decimal digit. The same conventions for choosing NNNN as for normal tests apply. Writing Tests ------------- The perf script starts much like a normal test script, except it sources perf-lib.sh: #!/bin/sh # # Copyright (c) 2005 Junio C Hamano # test_description='xxx performance test' . ./perf-lib.sh After that you will want to use some of the following: test_perf_fresh_repo # sets up an empty repository test_perf_default_repo # sets up a "normal" repository test_perf_large_repo # sets up a "large" repository test_perf_default_repo sub # ditto, in a subdir "sub" test_checkout_worktree # if you need the worktree too At least one of the first two is required! You can use test_expect_success as usual. In both test_expect_success and in test_perf, running "git" points to the version that is being perf-tested. The $MODERN_GIT variable points to the git wrapper for the currently checked-out version (i.e., the one that matches the t/perf scripts you are running). This is useful if your setup uses commands that only work with newer versions of git than what you might want to test (but obviously your new commands must still create a state that can be used by the older version of git you are testing). For actual performance tests, use test_perf 'descriptive string' ' command1 && command2 ' test_perf spawns a subshell, for lack of better options. This means that * you _must_ export all variables that you need in the subshell * you _must_ flag all variables that you want to persist from the subshell with 'test_export': test_perf 'descriptive string' ' foo=$(git rev-parse HEAD) && test_export foo ' The so-exported variables are automatically marked for export in the shell executing the perf test. For your convenience, test_export is the same as export in the main shell. This feature relies on a bit of magic using 'set' and 'source'. While we have tried to make sure that it can cope with embedded whitespace and other special characters, it will not work with multi-line data. Rather than tracking the performance by run-time as `test_perf` does, you may also track output size by using `test_size`. The stdout of the function should be a single numeric value, which will be captured and shown in the aggregated output. For example: test_perf 'time foo' ' ./foo >foo.out ' test_size 'output size' wc -c <foo.out ' might produce output like: Test origin HEAD ------------------------------------------------------------- 1234.1 time foo 0.37(0.79+0.02) 0.26(0.51+0.02) -29.7% 1234.2 output size 4.3M 3.6M -14.7% The item being measured (and its units) is up to the test; the context and the test title should make it clear to the user whether bigger or smaller numbers are better. Unlike test_perf, the test code will only be run once, since output sizes tend to be more deterministic than timings.