Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CodSpeed Benchmarks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this just generate an artifact that we can inspect to more easily identify where a performance impact occurred? Or will this do something more aggressive like blocking PRs that hurt performance against prior benchmarks?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't generate profiles or traces, but it does some sophisticated emulation work to produce stable benchmark results, which it then tracks in a project history.

It can comment on PRs which have significant performance impacts. And it defaults to blocking PRs which show a regression but I have explicitly turned that off for us. Here's how I configured it for now:

image

So if we have a perf regression it will tell us.


For a sample of what the PR comment looks like, I was experimenting with this in slyp over the weekend a little:
sirosen/slyp#34

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks; that's helpful


on:
push:
branches:
- "main"
pull_request:
# `workflow_dispatch` allows CodSpeed to trigger backtest
# performance analysis in order to generate initial data.
workflow_dispatch:

jobs:
benchmark:
name: run benchmarks
runs-on: ubuntu-latest
permissions:
contents: read
# required for OIDC authentication with CodSpeed
id-token: write

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1

# Only run codspeed benchmarking on the latest stable CPython version --
# not on a matrix of Pythons -- to maximize value while minimizing our
# resource usage.
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: "3.14"

- name: install tox
run: uv tool install tox --with tox-uv

- name: setup tox environment
run: tox run -e benchmark-codspeed --notest -vv

- name: benchmark
uses: CodSpeedHQ/action@373d6868929f444bc08d901fd0eb0ad52a8875ea # v5.2.1
with:
mode: simulation
run: tox run -e benchmark-codspeed
12 changes: 9 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,17 @@ commands =
pytest -n auto tests/non-pytest/lazy-imports/
pytest tests/unit/test_lazy_imports.py

[testenv:benchmark]
[testenv:benchmark,benchmark-codspeed]
# allow codspeed env vars to pass through; these are used to communicate with the
# web service when run in CI
passenv = CODSPEED_*
deps =
-r requirements/py{py_dot_ver}/test.txt
pytest-benchmark
commands = pytest {posargs:tests/benchmark/}
!codspeed: pytest-benchmark
codspeed: pytest-codspeed
commands =
!codspeed: pytest {posargs:tests/benchmark/}
codspeed: pytest --codspeed {posargs:tests/benchmark/}

[testenv:pylint,pylint-{py3.9,py3.10,py3.11,py3.12,py3.13,py3.14}]
deps = pylint
Expand Down
Loading