Skip to content

Run mutating benchmarks as copy plus operation in a loop - #1494

Merged
asvetlov merged 1 commit into
aio-libs:masterfrom
asvetlov:claude/benchmark-stability-e1710a
Sep 21, 2026
Merged

asvetlov merged 1 commit into
aio-libs:masterfrom
asvetlov:claude/benchmark-stability-e1710a

Conversation

@asvetlov

Copy link
Copy Markdown
Member

What do these changes do?

Reorganizes the mutating CodSpeed benchmarks to copy a base multidict and apply the operation 100 times per round, the way the add() and extend() benchmarks already work.

The insertion, update() and clear() benchmarks mutated one multidict shared across rounds, so only the first round measured the intended operation (later rounds replaced existing keys or cleared an empty dict). The pop(), popitem(), __delitem__(), __setitem__() and same-key add() benchmarks did a single copy per round, which let per-round overhead dominate. Working-set sizes per copy were reduced so the pure-Python legs stay at a similar per-round cost.

Are there changes in behavior for the user?

No, benchmarks only. Reported numbers for the touched benchmarks will shift since they now measure a different amount of work.

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, benchmark-only change
  • 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

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

Agent run details (optional, for reviewers)

Tests: pytest tests/test_multidict_benchmarks.py tests/test_views_benchmarks.py -q on 3.14t with the in-place C extension build: 269 passed (both c and py backend params).
CodSpeed walltime local run of touched benchmarks: all pass; pure-Python add_same_key ~0.4 s/round after shrinking to 100 values.
Lint: pre-commit hooks pass; mypy skipped because it crashes with an INTERNAL ERROR on the unmodified file too.

The insertion, update() and clear() benchmarks mutated a single
multidict shared across rounds, so only the first round measured the
intended operation. The pop(), popitem(), __delitem__(), __setitem__()
and same-key add() benchmarks did a single copy per round, letting
per-round overhead dominate. All of them now copy a base multidict and
apply the operation 100 times per round, matching the add() and
extend() benchmarks.
@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 08:39
@asvetlov
asvetlov requested a review from webknjaz as a code owner September 21, 2026 08:39
@codspeed

codspeed Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 98.05%

❌ 47 (👁 47) regressed benchmarks
✅ 219 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
👁 test_multidict_insert_str[cs-c] 345 µs 15,897.9 µs -97.83%
👁 test_multidict_popitem_str[ci-c] 1.7 ms 50.1 ms -96.62%
👁 test_multidict_popitem_str[cs-c] 1.1 ms 26.8 ms -96.02%
👁 test_multidict_update_str_with_kwargs[ci-c] 310.5 µs 33,675.7 µs -99.08%
👁 test_multidict_clear_str[ci-c] 20.4 µs 1,316.1 µs -98.45%
👁 test_multidict_pop_str[cs-c] 788.1 µs 24,359.2 µs -96.76%
👁 test_multidict_update_str[ci-c] 163.3 µs 17,424.3 µs -99.06%
👁 test_multidict_clear_str[cs-c] 20.1 µs 986.2 µs -97.97%
👁 test_multidict_update_str[cs-c] 83.5 µs 8,436 µs -99.01%
👁 test_multidict_delitem_str[ci-c] 886.5 µs 30,409.8 µs -97.08%
👁 test_multidict_update_str_with_kwargs[cs-c] 165.4 µs 15,401.8 µs -98.93%
👁 test_multidict_delitem_str[cs-c] 525.2 µs 15,413 µs -96.59%
👁 test_multidict_insert_str[ci-py] 16.8 ms 626 ms -97.31%
👁 test_multidict_popitem_str[ci-py] 9.7 ms 372 ms -97.39%
👁 test_multidict_pop_str[ci-py] 12.7 ms 482.4 ms -97.37%
👁 test_multidict_clear_str[ci-py] 90.5 µs 27,952.8 µs -99.68%
👁 test_multidict_update_str_with_kwargs[ci-py] 4.6 ms 684.9 ms -99.32%
👁 test_multidict_delitem_str[ci-py] 13.9 ms 512.2 ms -97.29%
👁 test_multidict_update_str[ci-py] 2.5 ms 313.4 ms -99.2%
👁 test_multidict_insert_str[cs-py] 16.1 ms 600.7 ms -97.31%
... ... ... ... ...

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


Comparing asvetlov:claude/benchmark-stability-e1710a (9f133a2) with master (1aea157)

Open in CodSpeed

@asvetlov
asvetlov enabled auto-merge (squash) September 21, 2026 08:47
@asvetlov
asvetlov disabled auto-merge September 21, 2026 08:47
@greptile-apps

greptile-apps Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

Safe to merge: the changed benchmark callbacks consistently operate on fresh copies and the benchmark suite passes.

What we checked:

  • Compared the previous callback shapes with the updated fresh-copy behavior and exercised all 24 changed variants for 100 repetitions against both the compiled and pure-Python implementations, asserting expected operation results and unchanged base inputs; the benchmark test suite ran through normal fixtures and all 169 tests passed. T-Rex
  • Before capture demonstrated the prior shared/single-copy callback shapes did not provide 100 fresh inputs, and after captures the fresh-copy validation against the loaded C extension and the pure-Python module succeeded; the authored source and runnable command were uploaded as artifacts. T-Rex

Reviews (1) · Last reviewed commit: "Run mutating benchmarks as copy plus ope..."

@asvetlov
asvetlov enabled auto-merge (squash) September 21, 2026 08:48
@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 (1aea157) to head (9f133a2).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1494   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           37        37           
  Lines         5983      6005   +22     
  Branches       521       536   +15     
=========================================
+ Hits          5983      6005   +22     
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 3954324 into aio-libs:master Sep 21, 2026
61 checks passed
@asvetlov
asvetlov deleted the claude/benchmark-stability-e1710a branch September 21, 2026 08:49
asvetlov added a commit that referenced this pull request Sep 21, 2026
)

<!-- Thank you for your contribution! -->

## 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

- [x] 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
- [x] Add a new news fragment into the `CHANGES/` folder
- [x] `make doc-spelling` passes and any new technical words are added
to `docs/spelling_wordlist.txt`

<details>
<summary>Agent run details (optional, for reviewers)</summary>

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.

</details>

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

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
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.

1 participant