1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-10 06:06:10 +02:00
git/t/perf
Jeff King 018b9deba5 pretty: lazy-load commit data when expanding user-format
When we expand a user-format, we try to avoid work that isn't necessary
for the output. For instance, we don't bother parsing the commit header
until we know we need the author, subject, etc.

But we do always load the commit object's contents from disk, even if
the format doesn't require it (e.g., just "%H"). Traditionally this
didn't matter much, because we'd have loaded it as part of the traversal
anyway, and we'd typically have those bytes attached to the commit
struct (or these days, cached in a commit-slab).

But when we have a commit-graph, we might easily get to the point of
pretty-printing a commit without ever having looked at the actual object
contents. We should push off that load (and reencoding) until we're
certain that it's needed.

I think the results of p4205 show the advantage pretty clearly (we serve
parent and tree oids out of the commit struct itself, so they benefit as
well):

  # using git.git as the test repo
  Test                          HEAD^             HEAD
  ----------------------------------------------------------------------
  4205.1: log with %H           0.40(0.39+0.01)   0.03(0.02+0.01) -92.5%
  4205.2: log with %h           0.45(0.44+0.01)   0.09(0.09+0.00) -80.0%
  4205.3: log with %T           0.40(0.39+0.00)   0.04(0.04+0.00) -90.0%
  4205.4: log with %t           0.46(0.46+0.00)   0.09(0.08+0.01) -80.4%
  4205.5: log with %P           0.39(0.39+0.00)   0.03(0.03+0.00) -92.3%
  4205.6: log with %p           0.46(0.46+0.00)   0.10(0.09+0.00) -78.3%
  4205.7: log with %h-%h-%h     0.52(0.51+0.01)   0.15(0.14+0.00) -71.2%
  4205.8: log with %an-%ae-%s   0.42(0.41+0.00)   0.42(0.41+0.01) +0.0%

  # using linux.git as the test repo
  Test                          HEAD^             HEAD
  ----------------------------------------------------------------------
  4205.1: log with %H           7.12(6.97+0.14)   0.76(0.65+0.11) -89.3%
  4205.2: log with %h           7.35(7.19+0.16)   1.30(1.19+0.11) -82.3%
  4205.3: log with %T           7.58(7.42+0.15)   1.02(0.94+0.08) -86.5%
  4205.4: log with %t           8.05(7.89+0.15)   1.55(1.41+0.13) -80.7%
  4205.5: log with %P           7.12(7.01+0.10)   0.76(0.69+0.07) -89.3%
  4205.6: log with %p           7.38(7.27+0.10)   1.32(1.20+0.12) -82.1%
  4205.7: log with %h-%h-%h     7.81(7.67+0.13)   1.79(1.67+0.12) -77.1%
  4205.8: log with %an-%ae-%s   7.90(7.74+0.15)   7.81(7.66+0.15) -1.1%

I added the final test to show where we don't improve (the 1% there is
just lucky noise), but also as a regression test to make sure we're not
doing anything stupid like loading the commit multiple times when there
are several placeholders that need it.

Reported-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-28 14:07:35 -08:00
..
repos
.gitignore
Makefile perf lint: add make test-lint to perf tests 2020-10-20 12:52:23 -07:00
README t/perf/README: elaborate on output format 2020-10-20 12:52:22 -07:00
aggregate.perl Merge branch 'jk/perf-wo-git-dot-pm' 2019-12-10 13:11:44 -08:00
bisect_regression Fix spelling errors in messages shown to users 2019-11-10 16:00:54 +09:00
bisect_run_script perf/bisect_run_script: disable codespeed 2018-05-06 13:04:54 +09:00
lib-pack.sh
min_time.perl
p0000-perf-lib-sanity.sh
p0001-rev-list.sh revision: use a prio_queue to hold rewritten parents 2019-04-04 18:21:54 +09:00
p0002-read-cache.sh t/helper: merge test-read-cache into test-tool 2018-03-27 08:45:47 -07:00
p0003-delta-base-cache.sh
p0004-lazy-init-name-hash.sh t/helper: merge test-lazy-init-name-hash into test-tool 2018-03-27 08:45:47 -07:00
p0005-status.sh
p0006-read-tree-checkout.sh
p0007-write-cache.sh t/helper: merge test-write-cache into test-tool 2018-03-27 08:45:47 -07:00
p0071-sort.sh t/helper: merge test-string-list into test-tool 2018-03-27 08:45:47 -07:00
p0100-globbing.sh
p1400-update-ref.sh p1400: use `git-update-ref --stdin` to test multiple transactions 2020-11-16 13:44:01 -08:00
p1450-fsck.sh fsck: add a performance test 2018-09-12 15:17:46 -07:00
p1451-fsck-skip-list.sh fsck: add a performance test for skipList 2018-09-12 15:17:46 -07:00
p3400-rebase.sh perf lint: add make test-lint to perf tests 2020-10-20 12:52:23 -07:00
p3404-rebase-interactive.sh
p4000-diff-algorithms.sh
p4001-diff-no-index.sh
p4205-log-pretty-formats.sh pretty: lazy-load commit data when expanding user-format 2021-01-28 14:07:35 -08:00
p4211-line-log.sh
p4220-log-grep-engines.sh
p4221-log-grep-engines-fixed.sh
p5302-pack-index.sh p5302: count up to online-cpus for thread tests 2020-08-21 12:02:36 -07:00
p5303-many-packs.sh packfile: actually set approximate_object_count_valid 2020-09-17 11:36:14 -07:00
p5304-prune.sh prune: use bitmaps for reachability traversal 2019-02-14 15:25:33 -08:00
p5310-pack-bitmaps.sh pack-bitmap: pass object filter to fill-in traversal 2020-05-04 21:57:58 -07:00
p5311-pack-bitmaps-fetch.sh pack-objects: default to writing bitmap hash-cache 2019-03-18 14:11:15 +09:00
p5550-fetch-tags.sh
p5551-fetch-rescan.sh
p5600-partial-clone.sh t/perf: add perf script for partial clones 2019-05-05 14:03:57 +09:00
p5601-clone-reference.sh t/perf: rename duplicate-numbered test script 2019-08-12 09:05:13 -07:00
p7000-filter-branch.sh
p7300-clean.sh
p7519-fsmonitor.sh p7519: allow running without watchman prereq 2021-01-06 13:48:25 -08:00
p7810-grep.sh
p7820-grep-engines.sh
p7821-grep-engines-fixed.sh
p9300-fast-import-export.sh fast-import: replace custom hash with hashmap.c 2020-04-06 13:41:24 -07:00
perf-lib.sh t/perf: avoid unnecessary test_export() recursion 2020-12-22 13:45:36 -08:00
run perf-lib.sh: forbid the use of GIT_TEST_INSTALLED 2019-05-08 11:00:28 +09:00

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.