Skip to content

Commit 90af158

Browse files
committed
ci(tests[benchmarks]): Add CodSpeed performance benchmarks
why: Track GitSync.obtain (and future hot paths) for performance regressions in CI. Replaces the long-stalled poetry-era #471 with a uv-native, functional-tests implementation against current master. what: - pyproject.toml: add `pytest-codspeed` to `testing` group; register a `benchmark` marker; deselect benchmarks by default via `addopts`; let mypy ignore missing `pytest_codspeed.*` stubs - tests/benchmarks/test_sync_git.py: add functional-style benchmark for `GitSync.obtain` against an initial-commit remote - .github/workflows/tests.yml: add `benchmarks` job using `CodSpeedHQ/action@v3` on pull requests and master pushes - CHANGES: note the benchmark addition under 0.41.x
1 parent d9391c3 commit 90af158

6 files changed

Lines changed: 204 additions & 3 deletions

File tree

.github/workflows/tests.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@ jobs:
5454
with:
5555
token: ${{ secrets.CODECOV_TOKEN }}
5656

57+
benchmarks:
58+
runs-on: ubuntu-latest
59+
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/master'
60+
steps:
61+
- uses: actions/checkout@v6
62+
- name: Install uv
63+
uses: astral-sh/setup-uv@v7
64+
with:
65+
enable-cache: true
66+
- name: Set up Python
67+
run: uv python install 3.14
68+
- name: Install dependencies
69+
run: uv sync --all-extras --dev
70+
- name: Run benchmarks via CodSpeed
71+
uses: CodSpeedHQ/action@v3
72+
with:
73+
token: ${{ secrets.CODSPEED_TOKEN }}
74+
run: uv run --group testing py.test tests/benchmarks --codspeed -m benchmark
75+
5776
release:
5877
runs-on: ubuntu-latest
5978
needs: build

CHANGES

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ $ uv add libvcs --prerelease allow
2020
_Notes on the upcoming release will go here._
2121
<!-- END PLACEHOLDER - ADD NEW CHANGELOG ENTRIES BELOW THIS LINE -->
2222

23+
### Development
24+
25+
#### CI: CodSpeed performance benchmarks
26+
27+
- Add `pytest-codspeed` to the `testing` dependency group
28+
- Register a `benchmark` marker (deselected by default; opt-in via `pytest tests/benchmarks --codspeed -m benchmark`)
29+
- Add `tests/benchmarks/test_sync_git.py` covering `GitSync.obtain` of an initial-commit remote
30+
- Add a dedicated `benchmarks` job in `.github/workflows/tests.yml` that runs the CodSpeed action on PRs and master pushes
31+
2332
## libvcs 0.40.0 (2026-04-25)
2433

2534
### What's new

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ testing = [
9797
"pytest-rerunfailures",
9898
"pytest-mock",
9999
"pytest-watcher",
100+
"pytest-codspeed",
100101
]
101102
coverage =[
102103
"codecov",
@@ -146,6 +147,10 @@ files = [
146147
"tests",
147148
]
148149

150+
[[tool.mypy.overrides]]
151+
module = ["pytest_codspeed.*"]
152+
ignore_missing_imports = true
153+
149154
[tool.coverage.run]
150155
branch = true
151156
parallel = true
@@ -231,7 +236,8 @@ addopts = [
231236
"--showlocals",
232237
"--doctest-docutils-modules",
233238
"-p no:doctest",
234-
"--reruns=2"
239+
"--reruns=2",
240+
"-m", "not benchmark",
235241
]
236242
doctest_optionflags = [
237243
"ELLIPSIS",
@@ -243,6 +249,9 @@ testpaths = [
243249
"docs",
244250
"README.md",
245251
]
252+
markers = [
253+
"benchmark: codspeed performance benchmark, deselected by default (run via `pytest tests/benchmarks --codspeed`)",
254+
]
246255
filterwarnings = [
247256
"ignore:The frontend.Option(Parser)? class.*:DeprecationWarning::",
248257
]

tests/benchmarks/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Benchmark tests run via pytest-codspeed."""

tests/benchmarks/test_sync_git.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Benchmark suite for git sync operations via pytest-codspeed."""
2+
3+
from __future__ import annotations
4+
5+
import typing as t
6+
7+
import pytest
8+
9+
from libvcs.pytest_plugin import CreateRepoFn
10+
from libvcs.sync.git import GitSync
11+
12+
if t.TYPE_CHECKING:
13+
import pathlib
14+
15+
from pytest_codspeed.plugin import BenchmarkFixture
16+
17+
18+
@pytest.mark.benchmark
19+
def test_git_obtain_initial_commit_repo(
20+
create_git_remote_repo: CreateRepoFn,
21+
tmp_path: pathlib.Path,
22+
benchmark: BenchmarkFixture,
23+
) -> None:
24+
"""Benchmark `GitSync.obtain` against a remote with one initial commit."""
25+
remote = create_git_remote_repo()
26+
repo = GitSync(url=f"file://{remote}", path=tmp_path / "checkout")
27+
28+
benchmark(repo.obtain)
29+
30+
assert repo.get_revision() == "initial"

0 commit comments

Comments
 (0)