Skip to content

Add benchmarks for adding many values for the same key - #1465

Merged
bdraco merged 1 commit into
masterfrom
add-same-key-benchmarks
Sep 15, 2026
Merged

bdraco merged 1 commit into
masterfrom
add-same-key-benchmarks

Conversation

@bdraco

@bdraco bdraco commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

What do these changes do?

Add benchmarks for adding many values for the same key. The current benchmarks use unique keys. It also adds a new construction benchmark.

Are there changes in behavior for the user?

no

Related issue number

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes

@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Sep 15, 2026
@greptile-apps

greptile-apps Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge.

The previously reported changelog naming issue is fully fixed: the fragment is now named CHANGES/1465.contrib.rst.

Reviews (2): Last reviewed commit: "Add benchmarks for adding many values fo..." | Re-trigger Greptile

Comment thread CHANGES/1465.contrib.rst Resolved
@bdraco
bdraco force-pushed the add-same-key-benchmarks branch from cef3719 to 0df9485 Compare September 15, 2026 05:35
@codspeed

codspeed Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 248 untouched benchmarks
🆕 12 new benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 test_create_multidict_with_items_same_key[ci-c] N/A 2.8 ms N/A
🆕 test_create_multidict_with_items_same_key[ci-py] N/A 955.9 ms N/A
🆕 test_create_multidict_with_items_same_key[cs-c] N/A 1.8 ms N/A
🆕 test_create_multidict_with_items_same_key[cs-py] N/A 954.3 ms N/A
🆕 test_create_multidict_with_many_items[ci-c] N/A 7.2 ms N/A
🆕 test_create_multidict_with_many_items[ci-py] N/A 92.8 ms N/A
🆕 test_create_multidict_with_many_items[cs-c] N/A 2.4 ms N/A
🆕 test_create_multidict_with_many_items[cs-py] N/A 86.3 ms N/A
🆕 test_multidict_add_same_key[ci-c] N/A 4.5 ms N/A
🆕 test_multidict_add_same_key[ci-py] N/A 1.5 s N/A
🆕 test_multidict_add_same_key[cs-c] N/A 3.2 ms N/A
🆕 test_multidict_add_same_key[cs-py] N/A 1.5 s N/A

Comparing add-same-key-benchmarks (0df9485) with master (c437773)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (9b1ba01) during the generation of this report, so c437773 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@aiolibsbot

Copy link
Copy Markdown
Contributor

PR Review — Add benchmarks for adding many values for the same key

Mergeable. The benchmarks measure a real gap in the suite, and the only note is a small mismatch with the PR description.

What's good:

  • Real gap. In the C code, _md_add_with_hash_steal_refs calls htkeys_find_empty_slot(keys, hash) without checking for an existing key. Adding the same key 1000 times means every insert starts probing from the same hash, so collision chains get long. The existing add/constructor benchmarks use 100 distinct keys and never hit this.
  • Two insert paths covered. test_multidict_add_same_key covers md.add. test_create_multidict_with_items_same_key covers the constructor path.
  • Follows the file's conventions. Each benchmark has its own name, as the header note asks (checked with git grep, no duplicates). Test data is built outside the timed _run. base_md.copy() keeps runs independent. any_multidict_class runs each benchmark against both MultiDict and CIMultiDict on both backends.
  • Fragment is correct. CHANGES/1465.contrib.rst is the right category for a contributor-facing change and credits :user:bdraco``. It is numbered for this PR. Greptile's earlier comment about a 1466 filename no longer applies at this head commit: the only matching file is `CHANGES/1465.contrib.rst`.

Needs attention:

  • The PR description only mentions same-key benchmarks. It leaves out the new 5000-unique-key constructor benchmark, which the fragment does mention.

Not checked: I couldn't run the new benchmarks, because this review shell has no Python. The code matches the pattern of the existing benchmarks in the file, and CI runs them with pytest --codspeed.


🟢 Suggestions

1. PR description leaves out the 5000-unique-key constructor benchmark
tests/test_multidict_benchmarks.py:580-588

The PR description only talks about same-key benchmarks ("The current benchmarks use unique keys"). This diff also adds test_create_multidict_with_many_items, which builds a multidict from 5000 unique keys. That covers a different case: how resizing and table growth scale, not repeated collisions on one key.

The CHANGES fragment does mention it ("and for creating a multidict with many items"), so this only affects how the PR reads. A reviewer going by the description would not expect a second benchmark family.

Fix: add one sentence to "What do these changes do?" saying that a large unique-key constructor benchmark was added, so there is a baseline to compare the same-key numbers against.

def test_create_multidict_with_many_items(
    benchmark: BenchmarkFixture, any_multidict_class: type[MultiDict[str]]
) -> None:
    items = [(str(i), str(i)) for i in range(5000)]

Checklist

  • Benchmark names are unique (file header forbids parametrize-style sharing)
  • Benchmark setup happens outside the timed body and runs don't share state
  • CHANGES fragment is named for the PR and uses the right category
  • PR description matches the diff — suggestion #1
  • No hardcoded secrets or unsafe operations

Automated review by Kōan (Claude) HEAD=0df9485 1 min 40s

@aiolibsbot

Copy link
Copy Markdown
Contributor

Note

No code changes since the last review (0df9485) — skipping. Push new commits or re-request a review to run again.

@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1465   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           32        32           
  Lines         5043      5061   +18     
  Branches       408       409    +1     
=========================================
+ Hits          5043      5061   +18     
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.

@bdraco
bdraco merged commit 36a0a20 into master Sep 15, 2026
58 of 59 checks passed
@bdraco
bdraco deleted the add-same-key-benchmarks branch September 15, 2026 05:47
@bdraco bdraco mentioned this pull request Sep 15, 2026
4 of 6 tasks
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