Skip to content

Benchmark re-initializing a populated multidict - #1620

Merged
asvetlov merged 1 commit into
aio-libs:masterfrom
asvetlov:bench-reinit
Sep 28, 2026
Merged

asvetlov merged 1 commit into
aio-libs:masterfrom
asvetlov:bench-reinit

Conversation

@asvetlov

Copy link
Copy Markdown
Member

What do these changes do?

Adds reinit_items (d.__init__(items)) and reinit_clone (d.__init__(other) with other of the same kind, the md_clone_from_ht() path) to benchmarks/operations.py, each at 200 and 20 items, plus four matching CodSpeed benchmarks. The existing ctor_* rows always build a fresh object whose table is empty, so replacing a live table (_md_install_keys(), #1619) was never measured; #1619 needed a one-off script.

The target stays populated after each call, so the setup hands back the same object and nothing is rebuilt inside the timed region. The rows are multidict-only: dict.__init__ on a live dict updates rather than replaces. Multidict-only rows are not rendered into docs/benchmark.rst, so the tables keep their shape and are not regenerated; the exclusion paragraph gained one sentence saying why re-initializing is left out. The CodSpeed tests carry no shard mark and run in shard 1 next to the create_* benchmarks; recent runs show the two shards within a few percent of each other on both builds.

Are there changes in behavior for the user?

No.

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

No; four rows in the registry and four CodSpeed tests following the existing patterns.

Related issue number

Follow-up to #1619.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist (callgrind_driver.py --self-check asserts the re-initialized size)
  • Documentation reflects the changes
  • 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.5); reviewed by @asvetlov.

Agent run details (optional, for reviewers)

New rows, instructions per operation, callgrind_driver.py --include-multidict-only, CPython 3.14.7, PYTHONHASHSEED=0, bracketed counting, drift 0:

Operation GIL MultiDict GIL CIMultiDict FT MultiDict FT CIMultiDict
reinit_items 45,484 56,424 68,102 78,442
reinit_items_small 4,860 5,840 7,322 8,242
reinit_clone 26,238 26,239 29,580 29,582
reinit_clone_small 2,686 2,687 3,275 3,276

For comparison, ctor_items is 44,850 / 55,930 (GIL) and 67,679 / 78,106 (FT); copy is 25,472 / 25,612 (GIL) and 29,063 / 29,150 (FT).

Tests: pytest -q passed on 3.14.7 GIL (2893 passed) and 3.14.7t FT (2881 passed) with the C extension; MULTIDICT_NO_EXTENSIONS=1 pytest -q --no-c-extensions passed from a clean tree copy (1356 passed); the reinit CodSpeed tests pass on 3.10 pure Python.
Self-check: callgrind_driver.py --self-check passed on both builds (140 cells).
Lint: pre-commit on the changed files and make doc-spelling passed.

Add reinit_items and reinit_clone operations, at 20 and 200 items, to the
benchmark registry, and matching CodSpeed benchmarks. The ctor_* rows
always construct a fresh object, so they never measured __init__
replacing a live table.
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Sep 28, 2026
@codspeed

codspeed Bot commented Sep 28, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 674 untouched benchmarks
🆕 32 new benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 test_reinit_multidict_from_same_kind_small[ci-c-ft] N/A 37 µs N/A
🆕 test_reinit_multidict_from_same_kind_small[ci-py-ft] N/A 209.9 µs N/A
🆕 test_reinit_multidict_from_same_kind_small[cs-c-ft] N/A 38.7 µs N/A
🆕 test_reinit_multidict_from_same_kind_small[cs-py-ft] N/A 205.1 µs N/A
🆕 test_reinit_multidict_from_same_kind[ci-c-ft] N/A 139.3 µs N/A
🆕 test_reinit_multidict_from_same_kind[ci-py-ft] N/A 908.3 µs N/A
🆕 test_reinit_multidict_from_same_kind[cs-c-ft] N/A 140.8 µs N/A
🆕 test_reinit_multidict_from_same_kind[cs-py-ft] N/A 897.2 µs N/A
🆕 test_reinit_multidict_with_items_small[ci-c-ft] N/A 45.3 µs N/A
🆕 test_reinit_multidict_with_items_small[ci-py-ft] N/A 665 µs N/A
🆕 test_reinit_multidict_with_items_small[cs-c-ft] N/A 45.6 µs N/A
🆕 test_reinit_multidict_with_items_small[cs-py-ft] N/A 627.1 µs N/A
🆕 test_reinit_multidict_with_items[ci-c-ft] N/A 168.8 µs N/A
🆕 test_reinit_multidict_with_items[ci-py-ft] N/A 4.2 ms N/A
🆕 test_reinit_multidict_with_items[cs-c-ft] N/A 165.2 µs N/A
🆕 test_reinit_multidict_with_items[cs-py-ft] N/A 3.9 ms N/A
🆕 test_reinit_multidict_from_same_kind_small[ci-c] N/A 33.4 µs N/A
🆕 test_reinit_multidict_from_same_kind_small[ci-py] N/A 198.6 µs N/A
🆕 test_reinit_multidict_from_same_kind_small[cs-c] N/A 35.5 µs N/A
🆕 test_reinit_multidict_from_same_kind_small[cs-py] N/A 193.9 µs N/A
... ... ... ... ...

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


Comparing asvetlov:bench-reinit (db23368) with master (43978bd)

Open in CodSpeed

@asvetlov
asvetlov marked this pull request as ready for review September 28, 2026 07:55
@asvetlov
asvetlov requested a review from webknjaz as a code owner September 28, 2026 07:55
@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Low risk] Adds benchmark tests for multidict re-initialization.

No identified issue blocks merging.

What we checked:

  • Validated general contract integrity by confirming that every call started and ended with the expected ordered content and size, with source content and object identity unchanged, clone sources remaining distinct same-kind mappings, and item sources remaining lists. T-Rex
  • Noted that no changed file or line has a confirmed defect, and that Callgrind instruction counts were not measured because Valgrind is unavailable. T-Rex

Reviews (1) · Last reviewed commit: "Benchmark re-initializing a populated mu..."

@codecov

codecov Bot commented Sep 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (43978bd) to head (db23368).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1620   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           44        44           
  Lines         8268      8292   +24     
  Branches       703       703           
=========================================
+ Hits          8268      8292   +24     
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 e04369b into aio-libs:master Sep 28, 2026
65 checks passed
@asvetlov
asvetlov deleted the bench-reinit branch September 28, 2026 08:07
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