| 1 |
name: update benchmark baselines |
| 2 |
|
| 3 |
"on": |
| 4 |
push: |
| 5 |
branches: |
| 6 |
- main |
| 7 |
paths: |
| 8 |
- flake.lock |
| 9 |
- flake.nix |
| 10 |
workflow_dispatch: |
| 11 |
inputs: |
| 12 |
ref: |
| 13 |
description: (optional) ref to benchmark for the new baseline |
| 14 |
required: false |
| 15 |
|
| 16 |
env: |
| 17 |
FORCE_COLOR: "1" |
| 18 |
PYTHONHASHSEED: "42" |
| 19 |
BASELINE_RELEASE_TAG: microbenchmarks |
| 20 |
|
| 21 |
jobs: |
| 22 |
update-baselines: |
| 23 |
runs-on: ubuntu-24.04 |
| 24 |
steps: |
| 25 |
- name: install valgrind |
| 26 |
uses: awalsh128/cache-apt-pkgs-action@553a35bb8ebd9fcabcb1c9451aa4c98e1b4ca8a9 |
| 27 |
with: |
| 28 |
packages: valgrind |
| 29 |
- name: check out source |
| 30 |
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 |
| 31 |
with: |
| 32 |
fetch-depth: 0 |
| 33 |
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.ref || github.ref }} |
| 34 |
- name: install Nix |
| 35 |
uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25 |
| 36 |
- name: resolve benchmark metadata |
| 37 |
id: metadata |
| 38 |
run: | |
| 39 |
mapfile -t python_info < <(nix develop .#benchmark --command bash -c "python - <<'PY' |
| 40 |
import platform |
| 41 |
print(platform.python_version()) |
| 42 |
print(platform.python_implementation()) |
| 43 |
PY") |
| 44 |
python_version=${python_info[0]} |
| 45 |
python_impl=${python_info[1]} |
| 46 |
python_series=${python_version%.*} |
| 47 |
arch=$(uname -m) |
| 48 |
versioned_asset_name="GHA-linux-cachegrind-${arch}-${python_impl}-${python_version}-baseline.json" |
| 49 |
series_asset_name="GHA-linux-cachegrind-${arch}-${python_impl}-${python_series}-baseline.json" |
| 50 |
versioned_instr_name="GHA-linux-cachegrind-${arch}-${python_impl}-${python_version}-instructions.txt" |
| 51 |
series_instr_name="GHA-linux-cachegrind-${arch}-${python_impl}-${python_series}-instructions.txt" |
| 52 |
{ |
| 53 |
echo "python_version=$python_version" |
| 54 |
echo "python_series=$python_series" |
| 55 |
echo "versioned_asset_name=$versioned_asset_name" |
| 56 |
echo "series_asset_name=$series_asset_name" |
| 57 |
echo "versioned_instr_name=$versioned_instr_name" |
| 58 |
echo "series_instr_name=$series_instr_name" |
| 59 |
} >> "$GITHUB_OUTPUT" |
| 60 |
- name: benchmark |
| 61 |
env: |
| 62 |
# Have cachegrind.py record its instruction estimate, which unlike the wall-clock |
| 63 |
# figures is reproducible, so PR runs can compare against it without a noise allowance. |
| 64 |
CACHEGRIND_ESTIMATE_OUT: ${{ github.workspace }}/instructions.txt |
| 65 |
run: | |
| 66 |
nix develop .#benchmark --command bash -c ' |
| 67 |
uv pip install --python "$VIRTUAL_ENV/bin/python" --no-deps . |
| 68 |
# Move aside the working tree package so we always import the installed version. |
| 69 |
mv -v bidict src |
| 70 |
./cachegrind.py pytest -c /dev/null -n0 \ |
| 71 |
--benchmark-autosave \ |
| 72 |
--benchmark-columns=min,rounds,iterations \ |
| 73 |
--benchmark-disable-gc \ |
| 74 |
--benchmark-group-by=name \ |
| 75 |
microbenchmarks.py |
| 76 |
' |
| 77 |
- name: prepare baseline assets |
| 78 |
id: assets |
| 79 |
run: | |
| 80 |
benchmark_json=$(find .benchmarks -type f -name '*.json' | sort | tail -n1) |
| 81 |
[ -n "$benchmark_json" ] |
| 82 |
cp "$benchmark_json" '${{ steps.metadata.outputs.versioned_asset_name }}' |
| 83 |
cp "$benchmark_json" '${{ steps.metadata.outputs.series_asset_name }}' |
| 84 |
[ -s instructions.txt ] |
| 85 |
cp instructions.txt '${{ steps.metadata.outputs.versioned_instr_name }}' |
| 86 |
cp instructions.txt '${{ steps.metadata.outputs.series_instr_name }}' |
| 87 |
{ |
| 88 |
echo "benchmark_json=$benchmark_json" |
| 89 |
echo "versioned_asset_path=${{ github.workspace }}/${{ steps.metadata.outputs.versioned_asset_name }}" |
| 90 |
echo "series_asset_path=${{ github.workspace }}/${{ steps.metadata.outputs.series_asset_name }}" |
| 91 |
echo "versioned_instr_path=${{ github.workspace }}/${{ steps.metadata.outputs.versioned_instr_name }}" |
| 92 |
echo "series_instr_path=${{ github.workspace }}/${{ steps.metadata.outputs.series_instr_name }}" |
| 93 |
} >> "$GITHUB_OUTPUT" |
| 94 |
- name: ensure baseline release exists |
| 95 |
env: |
| 96 |
GH_TOKEN: ${{ github.token }} |
| 97 |
run: | |
| 98 |
if gh release view "$BASELINE_RELEASE_TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then |
| 99 |
exit 0 |
| 100 |
fi |
| 101 |
gh release create "$BASELINE_RELEASE_TAG" \ |
| 102 |
--repo "$GITHUB_REPOSITORY" \ |
| 103 |
--title 'baseline microbenchmarks' \ |
| 104 |
--notes 'This tag exists merely so we have somewhere we can store the attached baseline benchmark data.' |
| 105 |
- name: upload baseline assets |
| 106 |
env: |
| 107 |
GH_TOKEN: ${{ github.token }} |
| 108 |
run: | |
| 109 |
gh release upload "$BASELINE_RELEASE_TAG" \ |
| 110 |
'${{ steps.assets.outputs.versioned_asset_path }}' \ |
| 111 |
'${{ steps.assets.outputs.series_asset_path }}' \ |
| 112 |
'${{ steps.assets.outputs.versioned_instr_path }}' \ |
| 113 |
'${{ steps.assets.outputs.series_instr_path }}' \ |
| 114 |
--repo "$GITHUB_REPOSITORY" \ |
| 115 |
--clobber |
| 116 |
- name: write summary |
| 117 |
run: | |
| 118 |
{ |
| 119 |
echo '### Uploaded benchmark baselines' |
| 120 |
echo |
| 121 |
echo '- Python: `${{ steps.metadata.outputs.python_version }}`' |
| 122 |
echo '- Versioned asset: `${{ steps.metadata.outputs.versioned_asset_name }}`' |
| 123 |
echo '- Series alias: `${{ steps.metadata.outputs.series_asset_name }}`' |
| 124 |
echo '- Source benchmark file: `${{ steps.assets.outputs.benchmark_json }}`' |
| 125 |
echo "- Instruction estimate: \`$(cat instructions.txt)\`" |
| 126 |
} >> "$GITHUB_STEP_SUMMARY" |
| 127 |
- name: archive benchmark results |
| 128 |
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a |
| 129 |
with: |
| 130 |
name: microbenchmark baseline results (CPython ${{ steps.metadata.outputs.python_version }}) |
| 131 |
path: | |
| 132 |
.benchmarks |
| 133 |
${{ steps.metadata.outputs.versioned_asset_name }} |
| 134 |
${{ steps.metadata.outputs.series_asset_name }} |
| 135 |
include-hidden-files: true |
| 136 |
if-no-files-found: error |
| 137 |
|
| 138 |
permissions: |
| 139 |
contents: write |