Skip to content

Run CodSpeed benchmarks on Python 3.14 and loop the smallest ones - #1498

Merged
asvetlov merged 8 commits into
aio-libs:masterfrom
asvetlov:claude/benchmarks-stability-46af47
Sep 21, 2026
Merged

asvetlov merged 8 commits into
aio-libs:masterfrom
asvetlov:claude/benchmarks-stability-46af47

Conversation

@asvetlov

@asvetlov asvetlov commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

What do these changes do?

Moves the CodSpeed benchmark job to Python 3.14, and makes the repr() and view inequality benchmarks repeat their operation 100 times, the way the other benchmarks already loop. The benchmark job timeout goes from 10 to 15 minutes, since the job takes about 9.5 minutes.

The high "variability" figures on the CodSpeed dashboard (up to about 140%) come from benchmark redefinitions in #1494 and from the real add() and getall() performance changes in #1466 and #1484, not from run-to-run noise. A same-commit rerun on master (242e5bd) reported 266 of 266 benchmarks unchanged. The dashboard window will age out by itself.

Are there changes in behavior for the user?

No, only benchmarks and CI change. The reshaped benchmarks, and the move to 3.14, will cause a one-time jump in their CodSpeed history.

Is it a substantial burden for the maintainers to support this?

No.

Related issue number

N/A

Checklist

  • I think the code is well written
  • Unit tests for the changes exist: N/A, this only changes benchmarks and CI
  • Documentation reflects the changes: N/A
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt: N/A
  • Add a new news fragment into the CHANGES/ folder
  • make doc-spelling passes and any new technical words are added to docs/spelling_wordlist.txt
Agent run details (optional, for reviewers)

Measurement: valgrind is not available locally, so a small pytest plugin emulated pytest-codspeed's simulation mode, including the gc.collect()/gc.disable() and random.seed(0) that plugin._measure does, followed by one warmup call and one measured call. It recorded user-space retired instructions with perf_event_open, pinned to P-cores. Each run allocated a different number of dummy objects first, to mimic unrelated heap changes between commits. The suite ran on CPython 3.15.0rc2 with PYTHONHASHSEED=0, 40 runs per variant, using the same seeds for both.

  • master benchmarks: every benchmark within 3.6% max/min spread; the worst was test_items_view_not_equals[ci-py], followed by test_values_view_repr[ci-c] at 2.4%.
  • this branch: every benchmark within 3.3% spread; the looped benchmarks all dropped below 2%.

An earlier revision also added a gc_disabled fixture, based on a harness that did not replicate pytest-codspeed's own GC handling. It was redundant and has been removed.

Tests (3.14.2): pytest passed (2059 passed, 21 skipped); pytest --no-c-extensions passed (1037 passed); pytest --codspeed --codspeed-mode simulation passed (269 benchmarks). 3.15 was tried first but dropped: setup-python has no prebuilt 3.15 yet, so the job compiled CPython and ran even longer.

Lint: pre-commit run on the changed files passed; make doc-spelling passed.

Drafted with Claude Code (Opus 5); reviewed by asvetlov.

Disable cyclic GC while a benchmark runs: with GC enabled, whether a
collection lands inside the single measured call, and which generation
it collects, depends on allocation counts left by earlier tests. A full
collection there moved test_create_multidict_with_many_items[cs-py] by
61% between otherwise identical runs.

Loop the repr() and view inequality benchmarks 100 times; at a few tens
of thousands of instructions per call, one allocator event was enough
to move them by 6-7%.

Run the benchmark job on Python 3.15.
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Sep 21, 2026
@asvetlov
asvetlov marked this pull request as ready for review September 21, 2026 10:12
@asvetlov
asvetlov requested a review from webknjaz as a code owner September 21, 2026 10:12
@greptile-apps

greptile-apps Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

Safe to merge.

Reviews (6) · Last reviewed commit: "Raise the benchmark job timeout to 15 mi..."

Comment thread tests/conftest.py Resolved
@greptile-apps

This comment has been minimized.

@codspeed

codspeed Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 78.13%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 4 improved benchmarks
❌ 58 (👁 58) regressed benchmarks
✅ 204 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_iterate_multidict_keys[cs-py] 395.5 µs 357 µs +10.77%
⚡ test_keys_view_less_or_equal[cs-py] 457.7 µs 415.1 µs +10.27%
⚡ test_iterate_multidict_items[cs-py] 456.1 µs 414.3 µs +10.09%
⚡ test_keys_view_less[cs-py] 467.4 µs 428 µs +9.21%
👁 test_create_multidictproxy 25.3 µs 28.1 µs -10.04%
👁 test_create_empty_multidictproxy 25.4 µs 28 µs -9.5%
👁 test_multidict_get_miss[cs-py] 888.2 µs 986 µs -9.92%
👁 test_multidict_extend_str_with_kwargs[ci-c] 43.7 ms 50.1 ms -12.66%
👁 test_multidict_repr[cs-py] 373.1 µs 29,543.9 µs -98.74%
👁 test_create_multidict_with_items[cs-py] 1.5 ms 1.8 ms -13.47%
👁 test_multidict_get_hit_with_default[cs-py] 948.2 µs 1,046.3 µs -9.38%
👁 test_create_multidict_with_dict[cs-py] 1.6 ms 1.9 ms -12.4%
👁 test_multidict_repr[ci-c] 152.8 µs 10,581.5 µs -98.56%
👁 test_create_multidict_with_items_with_kwargs[cs-py] 3.5 ms 4 ms -11.49%
👁 test_multidict_repr[cs-c] 156 µs 10,558.1 µs -98.52%
👁 test_multidict_pop_str[ci-py] 483.8 ms 535.7 ms -9.68%
👁 test_multidict_clear_str[ci-py] 28 ms 37.6 ms -25.62%
👁 test_multidict_extend_str[ci-py] 398.9 ms 456.8 ms -12.68%
👁 test_keys_view_not_equals[cs-c] 36.7 µs 447.8 µs -91.8%
👁 test_keys_view_repr[cs-c] 104.3 µs 3,087.6 µs -96.62%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing asvetlov:claude/benchmarks-stability-46af47 (c7f9546) with master (2a68472)

Open in CodSpeed

Comment thread tests/conftest.py Resolved
pytest-codspeed already runs gc.collect() and disables GC around each
measurement, so the fixture was redundant.
@asvetlov asvetlov changed the title Stabilize CodSpeed benchmarks and run them on Python 3.15 Run CodSpeed benchmarks on Python 3.15 and loop the smallest ones Sep 21, 2026
@asvetlov

Copy link
Copy Markdown
Member Author

@aiolibsbot rr

Comment thread CHANGES/1498.contrib.rst Resolved
asvetlov and others added 3 commits September 21, 2026 12:49
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
3.15 has no prebuilt setup-python build yet, so the job spent minutes
compiling CPython; with 3.14 the original 10-minute timeout is enough.
@asvetlov asvetlov changed the title Run CodSpeed benchmarks on Python 3.15 and loop the smallest ones Run CodSpeed benchmarks on Python 3.14 and loop the smallest ones Sep 21, 2026
@aiolibsbot

Copy link
Copy Markdown
Contributor

PR Review — Run CodSpeed benchmarks on Python 3.14 and loop the smallest ones

Merge-ready: a tight 17-line diff with all earlier review churn correctly cleaned up. Three non-blocking notes.

Specific things done well:

  • The branch was walked back properly. a6f5547 -> 912f3c1 removed the gc_disabled fixture entirely (verified: no gc reference remains anywhere in tests/conftest.py), and 51f3e4c reverted the 15-minute timeout that only the 3.15 experiment needed. The net diff against master is just the loops, the fragment, and two lines of workflow, with no leftovers from the abandoned approaches.
  • The 100x factor matches the established house pattern rather than inventing one: tests/test_multidict_benchmarks.py already wraps ~20 benchmarks in for _ in range(100), some with inner 100-200 element loops, and CHANGES.rst records the same scaling rationale for Scale up syscall-dominated CodSpeed benchmarks #1485. A concern that these repr loops would blow the benchmark job's cost budget does not hold up: test_multidict_popitem_str already does 100 copies plus 20,000 popitem() calls per measurement.
  • The benchmark selection is principled, not arbitrary. The looped inequality cases short-circuit on the first key, so they were genuinely the cheapest measurements in the file.
  • The changelog fragment is correctly numbered and categorised (contrib for CI/dev-experience), and CodSpeed already spell-checks clean via the existing codspeed wordlist entry plus prior use in CHANGES.rst.

What needs attention (all suggestions):

  • The visible CodSpeed report is from 3c7f05c, which predates the 3.14 switch and the restored 10-minute timeout, so the 3.14 leg is not yet proven green in the evidence on the PR; also consider quoting python-version to match "3.13" in hypothesis-gil.
  • 20 of 25 benchmarks in tests/test_views_benchmarks.py still measure one operation, and the branch's remaining 3.3% worst-case spread lives there; natural follow-up.
  • The interpreter bump and the benchmark reshape land as a single squashed data point, so the dashboard jump cannot be attributed to either; splitting or explicitly owning the choice would help.

No correctness, security, or dual-backend concerns: the diff touches only benchmark bodies and one CI version, and 3.14 is already the top of the test matrix.


🟢 Suggestions

1. 3.14 leg has no visible green benchmark run yet; consider quoting the version
.github/workflows/ci-cd.yml:418-422

Two small notes on this step, both non-blocking.

  • The only CodSpeed report posted on the PR compares 3c7f05c against master, and 3c7f05c predates the 3.14 switch (51f3e4c), which also restored timeout-minutes from 15 back to 10. So the evidence visible here does not yet show the benchmark job passing on 3.14 within the 10-minute budget. The risk is narrow but concrete: if pytest-codspeed==5.0.3 (pinned in requirements/pytest.txt) has no cp314 wheel, py-dependency-install builds it from source and eats the budget the same way the 3.15 attempt did. Worth confirming the job on the current head is green before merging rather than after.

  • python-version: 3.14 is unquoted, so YAML parses it as a float. That round-trips fine for 3.14, and it matches what the line said before (3.13), but hypothesis-gil a few jobs below uses python-version: "3.13". Quoting here would make the two consistent and remove the trailing-zero foot-gun for a future bump (3.20 would silently become 3.2).

    - name: Setup Python 3.14
      id: python-install
      uses: actions/setup-python@v7
      with:
        python-version: 3.14
2. Interpreter bump and benchmark reshape land as one data point
CHANGES/1498.contrib.rst:1-3

The fragment (correctly) describes two independent changes: the 100x loops and the 3.13 -> 3.14 move. Both perturb CodSpeed history at once, and since this repo lands PRs squashed, the dashboard gets a single commit carrying both. The posted report already mixes the two effects: the ~100x deltas on the looped benchmarks sit next to 9-17% swings on untouched ones such as test_multidict_get_miss and test_create_multidict_with_dict, which are presumably the interpreter change.

AGENTS.md rule 8 asks for one logical change per PR, and here the practical cost is attribution: nobody looking at the step in six months can tell which part of it came from 3.14. Landing the CI bump separately (the benchmark bodies do not depend on it) would keep each jump readable.

If the preference is to take the whole discontinuity in one go and be done with it, that is a reasonable call too; it is worth stating explicitly in the PR body as the deliberate choice.

The ``repr()`` and view inequality benchmarks were updated to repeat their
operation in a loop, like the other benchmarks, and the CodSpeed benchmark
job was moved to Python 3.14 -- by :user:`asvetlov`.

Checklist

  • Diff delivers what the description promises (loops + 3.14 move)
  • No scope creep or leftovers from abandoned revisions (gc fixture, 15-min timeout)
  • CHANGES fragment present, correctly numbered and categorised — suggestion #2
  • Docs spelling safe for new technical words
  • Benchmark cost stays within the existing suite envelope
  • CI change proven green on the reviewed head — suggestion #1
  • One logical change per PR (AGENTS.md rule 8) — suggestion #2
  • No dual-backend divergence (benchmarks run on both legs)
  • No security-relevant surface touched

Automated review by Kōan (Claude) HEAD=51f3e4c 5 min 37s

@aiolibsbot

Copy link
Copy Markdown
Contributor

Rebase with requested adjustments

Branch claude/benchmarks-stability-46af47 was rebased onto master and review feedback was applied.

Changes applied

  • Quoted python-version: "3.14" in the benchmark job (.github/workflows/ci-cd.yml:422), matching the hypothesis-gil job and avoiding YAML float truncation on a future bump.

Not changed (and why)

  • Greptile's two tests/conftest.py GC-state comments: obsolete. gc_disabled was removed in b540af6; pytest-codspeed disables GC around each measurement itself. Greptile confirmed and withdrew the finding.
  • "No visible green benchmark run on 3.14 yet": not a code change. timeout-minutes is 10 on current head (the 15-minute bump was reverted); the 3.14 leg needs a green run before merge. Human verification item.
  • "Interpreter bump and benchmark reshape land as one data point": disagree with splitting. Both perturb CodSpeed history; splitting produces two discontinuities instead of one, and neither jump becomes readable, since the loop change is a ~100x step that dwarfs the interpreter delta either way. Deliberate choice to take the discontinuity once. PR body is external, so add that sentence there if you want it stated explicitly.

Stats

4 files changed, 17 insertions(+), 8 deletions(-)
Actions performed
  • Already-solved check: negative (confidence=high, reasoning=Master still runs the CodSpeed job on Python 3.13 and the repr()/view-inequality benchmarks still ex)
  • Rebased claude/benchmarks-stability-46af47 onto upstream/master
  • Applied review feedback
  • Pre-push CI check: previous run still pending
  • Force-pushed claude/benchmarks-stability-46af47 to origin
  • Private review gate skipped: disabled by config
  • Force-push guard: all original PR content verified preserved
  • CI check enqueued in ## CI (async)

CI status

CI will be checked asynchronously.


Automated by Kōan

The job takes about 9.5 minutes on 3.14, too close to the 10-minute cap.
@codecov

codecov Bot commented Sep 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (cd528d6) to head (c7f9546).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1498   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           37        37           
  Lines         6021      6075   +54     
  Branches       538       544    +6     
=========================================
+ Hits          6021      6075   +54     
Flag Coverage Δ
CI-GHA 100.00% <100.00%> (ø)
pytest 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@asvetlov
asvetlov merged commit 563f667 into aio-libs:master Sep 21, 2026
75 of 79 checks passed
@asvetlov
asvetlov deleted the claude/benchmarks-stability-46af47 branch September 21, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants