Skip to content

Benchmark the shapes where an allocation is most of the work - #1556

Merged
asvetlov merged 2 commits into
aio-libs:masterfrom
asvetlov:claude/benchmark-small-mappings
Sep 24, 2026
Merged

asvetlov merged 2 commits into
aio-libs:masterfrom
asvetlov:claude/benchmark-small-mappings

Conversation

@asvetlov

Copy link
Copy Markdown
Member

What do these changes do?

The registry measured every operation on a 200-item mapping. The
allocation an operation makes is a fixed cost, so at that size it was
divided across 200 entries and all but disappeared: d.items()
measured 1.7% faster under #1541 where it is in fact 46% faster, and
the shell pools looked marginal when they are not.

Six operations are added for the shapes where the allocation is most of
the work: cls(), cls(items) and d.copy() at 20 items, d.items()
and iter(d) taken without being consumed, and Proxy(d). The last
needs a proxy type per implementation, so Impl gains load_proxy and
Operation a proxy flag, mirroring how istr already works.

The generated tables in docs/benchmark.rst are regenerated, so their
numbers also move to current master.

Are there changes in behavior for the user?

No. Nothing outside benchmarks/ and docs/ changes.

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

No. The new cases reuse the existing Case shape and the existing
runners; callgrind_driver.py --self-check covers them.

Related issue number

None.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist — N/A, benchmarks/ has no suite; --self-check runs every cell
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt — N/A, already listed
  • 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)

What the new cases say about the two shell-pool PRs, instructions per
operation, GIL build:

#1541 against its parent 130bd92:

operation MultiDict CIMultiDict
d.items() -46.3% -34.3%
iter(d) -41.0% -41.0%
for k in d, 200 keys -1.7% -1.7%

#1542 against 51c75e4:

operation MultiDict CIMultiDict
cls() -28.8% -23.3%
Proxy(d) -28.6% -22.9%
d.copy(), 20 items -9.7% -8.1%
cls(items), 20 items -4.9% -3.3%
cls(items), 200 items -0.5% -0.3%

callgrind_driver.py --self-check passes at 124 cells. Tables collected
on CPython 3.14.7 GIL and 3.14.7t, PYTHONHASHSEED=0, client-request
bracketing, matching the environment the previous tables recorded.

Drafted with Claude Opus 5; reviewed by @asvetlov.

@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Sep 24, 2026
@asvetlov
asvetlov force-pushed the claude/benchmark-small-mappings branch from cfabc6a to ffe7cb1 Compare September 24, 2026 08:25
@asvetlov
asvetlov marked this pull request as ready for review September 24, 2026 08:29
@asvetlov
asvetlov requested a review from webknjaz as a code owner September 24, 2026 08:29
@greptile-apps

greptile-apps Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The documentation mismatch is non-blocking; the PR can merge with this issue outstanding.

Reviews (1) · Last reviewed commit: "Regenerate the benchmark tables"

Comment thread docs/benchmark.rst Resolved
@greptile-apps

greptile-apps Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff

These findings sit on lines the diff does not cover, so they could not be posted inline. Each one leaves this list once its file changes.

  • P2 Benchmark description omits the empty and 20-item cases ▶

    • Bug
      • docs/benchmark.rst:51–55 says each published row uses a 200-key mapping except d.update(other). The published cls() row at line 102 constructs an empty mapping; cls(items), 20 items at line 107 and d.copy(), 20 items at line 117 use 20 items.
    • Cause
      • The generated tables gained rows for benchmark operations with empty or 20-item inputs without updating the blanket description.
    • Fix
      • Qualify the 200-key statement to exclude the explicitly labeled empty and 20-item rows.

@codspeed

codspeed Bot commented Sep 24, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 310 untouched benchmarks


Comparing asvetlov:claude/benchmark-small-mappings (ffe7cb1) with master (cd92a6c)

Open in CodSpeed

@codecov

codecov Bot commented Sep 24, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1556   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           41        41           
  Lines         7001      7014   +13     
  Branches       610       610           
=========================================
+ Hits          7001      7014   +13     
Flag Coverage Δ
CI-GHA 100.00% <ø> (ø)
pytest 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 da7729c into aio-libs:master Sep 24, 2026
62 checks passed
@asvetlov
asvetlov deleted the claude/benchmark-small-mappings branch September 24, 2026 08:43
asvetlov added a commit that referenced this pull request Sep 24, 2026
<!-- Thank you for your contribution! -->

## What do these changes do?

"What is measured" says every row uses a mapping of 200 keys, with
`d.update(other)` as the only exception. Since #1556 that is no longer
true: `cls()` builds an empty mapping and two rows use 20 items, so a
reader comparing them against the 200-key rows would draw the wrong
conclusion. This says which rows those are and why they differ.

## Are there changes in behavior for the user?

No. Prose only; no measurement or table changes.

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

No.

## Related issue number

Follows up #1556.

## Checklist

- [x] I think the code is well written
- [x] Unit tests for the changes exist — N/A, documentation only
- [x] Documentation reflects the changes
- [ ] If you provide code modification, please add yourself to
`CONTRIBUTORS.txt` — N/A, already listed
- [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`

Drafted with Claude Opus 5; reviewed by @asvetlov.
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