From 6fedfd3237f4e9066bdb64f38b8366b40298d476 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Tue, 29 Oct 2024 15:23:39 -0400 Subject: [PATCH] Add benchmark for large-ish (250mb) index-pack --- .github/workflows/benchmark.yml | 14 ++++-- tests/benchmarks/benchmark_helpers.sh | 65 ++++++++++++++++++++++++--- tests/benchmarks/indexpack__250mb | 11 +++++ 3 files changed, 80 insertions(+), 10 deletions(-) create mode 100755 tests/benchmarks/indexpack__250mb diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 3fb912d40..8299c3e56 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -70,9 +70,14 @@ jobs: if: matrix.platform.setup-script != '' - name: Clone resource repositories run: | - mkdir resources + # we need a superior way to package the benchmark resources; lfs + # is too expensive + # git lfs install + # git clone https://github.com/libgit2/benchmark-resources resources git clone --bare https://github.com/git/git resources/git - git clone --bare https://github.com/torvalds/linux resources/linux + # avoid linux temporarily; the linux blame benchmarks are simply + # too slow to use + # git clone --bare https://github.com/torvalds/linux resources/linux - name: Build run: | mkdir build && cd build @@ -80,10 +85,11 @@ jobs: shell: bash - name: Benchmark run: | - export BENCHMARK_GIT_REPOSITORY="$(pwd)/resources/git" + export BENCHMARK_RESOURCES_PATH="$(pwd)/resources" + export BENCHMARK_GIT_PATH="$(pwd)/resources/git" # avoid linux temporarily; the linux blame benchmarks are simply # too slow to use - # export BENCHMARK_LINUX_REPOSITORY="$(pwd)/resources/linux" + # export BENCHMARK_LINUX_PATH="$(pwd)/resources/linux" if [[ "$(uname -s)" == MINGW* ]]; then GIT2_CLI="$(cygpath -w $(pwd))\\build\\Release\\git2" diff --git a/tests/benchmarks/benchmark_helpers.sh b/tests/benchmarks/benchmark_helpers.sh index 5143a01fc..0ff6b03ef 100644 --- a/tests/benchmarks/benchmark_helpers.sh +++ b/tests/benchmarks/benchmark_helpers.sh @@ -23,6 +23,7 @@ fi HELP_GIT_REMOTE="https://github.com/git/git" HELP_LINUX_REMOTE="https://github.com/torvalds/linux" +HELP_RESOURCE_REPO="https://github.com/libgit2/benchmark-resources" # # parse the arguments to the outer script that's including us; these are arguments that @@ -205,6 +206,30 @@ create_preparescript() { cp -R "\${RESOURCES_DIR}/\${RESOURCE}" "\${SANDBOX_DIR}/" } + sandbox_resource() { + RESOURCE="\${1}" + + if [ "\${RESOURCE}" = "" ]; then + echo "usage: sandbox_resource " 1>&2 + exit 1 + fi + + RESOURCE_UPPER=\$(echo "\${RESOURCE}" | tr '[:lower:]' '[:upper:]' | sed -e "s/-/_/g") + RESOURCE_PATH=\$(eval echo "\\\${BENCHMARK_\${RESOURCE_UPPER}_PATH}") + + if [ "\${RESOURCE_PATH}" = "" -a "\${BENCHMARK_RESOURCES_PATH}" != "" ]; then + RESOURCE_PATH="\${BENCHMARK_RESOURCES_PATH}/\${RESOURCE}" + fi + + if [ ! -f "\${RESOURCE_PATH}" ]; then + echo "sandbox: the resource \"\${RESOURCE}\" does not exist" + exit 1 + fi + + rm -rf "\${SANDBOX_DIR:?}/\${RESOURCE}" + cp -R "\${RESOURCE_PATH}" "\${SANDBOX_DIR}/\${RESOURCE}" + } + sandbox_repo() { RESOURCE="\${1}" @@ -229,8 +254,8 @@ create_preparescript() { exit 1 fi - REPO_UPPER=\$(echo "\${1}" | tr '[:lower:]' '[:upper:]') - REPO_URL=\$(eval echo "\\\${BENCHMARK_\${REPO_UPPER}_REPOSITORY}") + REPO_UPPER=\$(echo "\${REPO}" | tr '[:lower:]' '[:upper:]') + REPO_URL=\$(eval echo "\\\${BENCHMARK_\${REPO_UPPER}_PATH}") if [ "\${REPO_URL}" = "" ]; then echo "\$0: unknown repository '\${REPO}'" 1>&2 @@ -397,17 +422,45 @@ needs_repo() { exit 1 fi - REPO_UPPER=$(echo "${1}" | tr '[:lower:]' '[:upper:]') - REPO_URL=$(eval echo "\${BENCHMARK_${REPO_UPPER}_REPOSITORY}") + REPO_UPPER=$(echo "${REPO}" | tr '[:lower:]' '[:upper:]') + REPO_PATH=$(eval echo "\${BENCHMARK_${REPO_UPPER}_PATH}") REPO_REMOTE_URL=$(eval echo "\${HELP_${REPO_UPPER}_REMOTE}") - if [ "${REPO_URL}" = "" ]; then + if [ "${REPO_PATH}" = "" ]; then echo "$0: '${REPO}' repository not configured" 1>&2 echo "" 1>&2 echo "This benchmark needs an on-disk '${REPO}' repository. First, clone the" 1>&2 - echo "remote repository ('${REPO_REMOTE_URL}') locally then set," 1>&2 + echo "remote repository ('${REPO_REMOTE_URL}') locally then set" 1>&2 echo "the 'BENCHMARK_${REPO_UPPER}_REPOSITORY' environment variable to the path that" 1>&2 echo "contains the repository locally, then run this benchmark again." 1>&2 exit 2 fi } + +# helper script to give useful error messages about configuration +needs_resource() { + RESOURCE="${1}" + + if [ "${RESOURCE}" = "" ]; then + echo "usage: needs_resource " 1>&2 + exit 1 + fi + + RESOURCE_UPPER=$(echo "${RESOURCE}" | tr '[:lower:]' '[:upper:]' | sed -e "s/-/_/g") + RESOURCE_PATH=$(eval echo "\${BENCHMARK_${RESOURCE_UPPER}_PATH}") + + if [ "${RESOURCE_PATH}" = "" -a "${BENCHMARK_RESOURCES_PATH}" != "" ]; then + RESOURCE_PATH="${BENCHMARK_RESOURCES_PATH}/${RESOURCE}" + fi + + if [ "${RESOURCE_PATH}" = "" ]; then + echo "$0: '${RESOURCE}' resource path not configured" 1>&2 + echo "" 1>&2 + echo "This benchmark needs an on-disk resource named '${RESOURCE}'." 1>&2 + echo "First, clone the additional benchmark resources locally (from" 1>&2 + echo "'${HELP_RESOURCE_REPO}'), then set the" 1>& 2 + echo "'BENCHMARK_RESOURCES_PATH' environment variable to the path that" 1>&2 + echo "contains the resources locally, then run this benchmark again." 1>&2 + exit 2 + fi +} diff --git a/tests/benchmarks/indexpack__250mb b/tests/benchmarks/indexpack__250mb new file mode 100755 index 000000000..5bd964786 --- /dev/null +++ b/tests/benchmarks/indexpack__250mb @@ -0,0 +1,11 @@ +#!/bin/bash -e + +. "$(dirname "$0")/benchmark_helpers.sh" + +needs_resource packfile-250mb + +gitbench --prepare "git init --bare dest.git && sandbox_resource packfile-250mb && mv packfile-250mb dest.git/packfile-250mb.pack" \ + --warmup 5 \ + --chdir "dest.git" \ + -- \ + index-pack packfile-250mb.pack