Skip to content

Commit a49b5ac

Browse files
authored
On demand pull request benchmark (#5286)
* Enable on-demand benchmarking of a pull request. * Better benchmark debug printing. * PR benchmarking instructions. * Specify conda_channels in asv.conf.json . * Use GitHub markdown for benchmark_this label. * What's New entry.
1 parent 54da9df commit a49b5ac

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

.github/workflows/benchmark.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ on:
1212
description: "Argument to be passed to the overnight benchmark script."
1313
required: false
1414
type: string
15+
pull_request:
16+
types: [labeled]
1517

1618
jobs:
1719
benchmark:
18-
if: "github.repository == 'SciTools/iris'"
20+
if: >
21+
github.repository == 'SciTools/iris' &&
22+
(github.event_name != 'pull_request' ||
23+
github.event.label.name == 'benchmark_this')
1924
runs-on: ubuntu-latest
2025

2126
env:
@@ -67,7 +72,14 @@ jobs:
6772
run: |
6873
echo "OVERRIDE_TEST_DATA_REPOSITORY=${GITHUB_WORKSPACE}/${IRIS_TEST_DATA_PATH}/test_data" >> $GITHUB_ENV
6974
75+
- name: Benchmark this pull request
76+
if: ${{ github.event.label.name == 'benchmark_this' }}
77+
run: |
78+
git checkout ${{ github.head_ref }}
79+
python benchmarks/bm_runner.py branch origin/${{ github.base_ref }}
80+
7081
- name: Run overnight benchmarks
82+
if: ${{ github.event_name != 'pull_request' }}
7183
run: |
7284
first_commit=${{ inputs.first_commit }}
7385
if [ "$first_commit" == "" ]
@@ -81,6 +93,7 @@ jobs:
8193
fi
8294
8395
- name: Create issues for performance shifts
96+
if: ${{ github.event_name != 'pull_request' }}
8497
env:
8598
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8699
run: |

benchmarks/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ shifts in performance being flagged in a new GitHub issue.
1111

1212
## Running benchmarks
1313

14+
On GitHub: a Pull Request can be benchmarked by adding the
15+
https://github.com/SciTools/iris/labels/benchmark_this
16+
label to the PR (to run a second time: just remove and re-add the label).
17+
Note that a benchmark run could take an hour or more to complete.
18+
This runs a comparison between the PR branch's ``HEAD`` and its merge-base with
19+
the PR's base branch, thus showing performance differences introduced
20+
by the PR. (This run is managed by
21+
[the aforementioned GitHub Action](../.github/workflows/benchmark.yml)).
22+
1423
`asv ...` commands must be run from this directory. You will need to have ASV
1524
installed, as well as Nox (see
1625
[Benchmark environments](#benchmark-environments)).

benchmarks/asv.conf.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"project_url": "https://github.com/SciTools/iris",
55
"repo": "..",
66
"environment_type": "conda-delegated",
7+
"conda_channels": ["conda-forge", "defaults"],
78
"show_commit_url": "http://github.com/scitools/iris/commit/",
89
"branches": ["upstream/main"],
910

benchmarks/bm_runner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333

3434

3535
def _subprocess_run_print(args, **kwargs):
36-
print(f"BM_RUNNER DEBUG: {' '.join(args)}")
36+
# Use subprocess for printing to reduce chance of printing out of sequence
37+
# with the subsequent calls.
38+
subprocess.run(["echo", f"BM_RUNNER DEBUG: {' '.join(args)}"])
3739
return subprocess.run(args, **kwargs)
3840

3941

docs/src/developers_guide/contributing_benchmarks.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ requests, instead it is **run overnight against each the commits of the
2222
previous day** to check if any commit has introduced performance shifts.
2323
Detected shifts are reported in a new Iris GitHub issue.
2424

25+
.. _on_demand_pr_benchmark:
26+
2527
If a pull request author/reviewer suspects their changes may cause performance
26-
shifts, a convenience script is available to replicate the
27-
overnight benchmark run but comparing the current ``HEAD`` with a requested
28-
branch (e.g. ``upstream/main``). Read more in `benchmarks/README.md`_.
28+
shifts, they can manually order their pull request to be benchmarked by adding
29+
the ``benchmark_this`` label to the PR. Read more in `benchmarks/README.md`_.
2930

3031
Other Uses
3132
----------

docs/src/whatsnew/latest.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ This document explains the changes made to Iris for this release
119119
#. `@bjlittle`_ adopted `pypa/build`_ recommended best practice to build a
120120
binary ``wheel`` from the ``sdist``. (:pull:`5266`)
121121

122+
#. `@trexfeathers`_ enabled on-demand benchmarking of Pull Requests; see
123+
:ref:`here <on_demand_pr_benchmark>`. (:pull:`5286`)
124+
122125

123126
.. comment
124127
Whatsnew author names (@github name) in alphabetical order. Note that,

0 commit comments

Comments
 (0)