Repository navigation
Pass the entry identity's hash to the ForEach visitor - #1561
Merged
asvetlov merged 2 commits intoSep 24, 2026
Merged
Conversation
The visitor already receives the entry's identity; add the hash the mapping stores alongside it, so a visitor bucketing or grouping entries of its own does not have to hash the identity again. MultiDict_ItemVisitor now takes (user_data, identity, hash, key, value), with the hash next to the identity it belongs to. MultiDict_CyItemVisitor gains it in the same position, keeping its own user_data-last order. The internal md_item_visitor_t is widened to match, along with both walks and their two in-tree visitors. md_walk_with_hash passes the hash it was already handed, which every matched entry's own hash equals by the walk's own predicate. md_walk_all reads entry->hash before the visitor call, next to the identity and value it already reads there, since _md_ensure_key() and the visitor can both run Python code that frees the entry. The capsule is still unreleased and MultiDict_CAPI_VERSION is still 1, so the typedef changes in place rather than growing a parallel entry point.
asvetlov
marked this pull request as ready for review
September 24, 2026 10:45
Contributor
|
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1561 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 41 41
Lines 7014 7074 +60
Branches 610 615 +5
=========================================
+ Hits 7014 7074 +60
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
4 of 6 tasks
asvetlov
added a commit
that referenced
this pull request
Sep 26, 2026
<!-- Thank you for your contribution! --> ## What do these changes do? Prepares the news fragments for 7.0.0. The public C API (#1480) and the watchers API (#1551) are new in this release, so the fragments describing later changes to them describe states that never shipped. They are folded into the entries that added the APIs: the visitor's identity and hash (#1552, #1561) into `1478`, and the 32-watcher limit, the watcher registration race fix and the failing-callback report (#1574, #1583, #1585) into `1551`. The `MultiDict_SetDefault(NULL)` half of `1553` is dropped for the same reason. Intermediate header names that never shipped are removed as well: `1510` no longer mentions `deferred_decref.h`, which #1530 merged into `reflist.h`, and `1513` names `debug.h` directly, so `1576` goes. `1572`, a fix to a tool added this cycle, is folded into `1529`. `1560` and the last sentence of `1556` go too, since the release refresh of the benchmark tables supersedes those intermediate ones. Finally, the fragments that did not lead with a past-tense verb or described the change as "now ..." are rewritten per `AGENTS.md`. The benchmark table refresh from `RELEASE.md` step 2 is still to be added to this branch before it leaves draft. ## Are there changes in behavior for the user? No. ## 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, changelog only) - [x] 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 (N/A, edits existing fragments; the benchmark refresh will add a `doc` fragment) - [x] `make doc-spelling` passes and any new technical words are added to `docs/spelling_wordlist.txt` Drafted with Claude Code (Claude Opus 5.5); pending review by @asvetlov before leaving draft. <details> <summary>Agent run details (optional, for reviewers)</summary> `python -Im towncrier build --draft --version 7.0.0` renders cleanly. The symlinked pairs `1512` -> `1492` and `1562` -> `1555`, and both `1535` fragments, are intentional and left alone. </details>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What do these changes do?
The
ForEachvisitor gained the entry's identity in #1552, but notthe hash the mapping stores alongside it. A visitor that buckets or
groups entries by identity therefore had to hash it again, work both
walks had already done.
MultiDict_ItemVisitornow takes(void *user_data, PyObject *identity, Py_hash_t hash, PyObject *key, PyObject *value), with the hash next to the identity it belongs to.MultiDict_CyItemVisitorgains it in the same position, keeping itsown
user_data-last order. The internalmd_item_visitor_tin_multilib/walk.his widened to match, along withmd_walk_all,md_walk_with_hashand their two in-tree visitors.md_walk_with_hashpasses the hash it was already handed; everymatched entry's own
entry->hashequals it, since that is the firsthalf of the walk's match predicate.
md_walk_allreadsentry->hashbefore the visitor call, alongside the identity and value it already
reads there, since
_md_ensure_key()and the visitor can both runPython code that frees the entry.
The capsule is unreleased: it landed in #1480, after v6.9.1, and
MultiDict_CAPI_VERSIONis still 1, so no client can have been builtagainst the narrower signature. That is why the typedef changes in
place instead of growing a parallel entry point at the end of the
struct with a version bump.
Are there changes in behavior for the user?
No, for Python-level users. A C or Cython client of the capsule has to
take the extra parameter, but the capsule has not shipped in a release
yet, so there is nothing to migrate.
Is it a substantial burden for the maintainers to support this?
No. Both walks have the hash in hand already, so the wider signature
costs neither a lookup nor a reference.
This one does not move the benchmarks. On the GIL build no
C-extension row changed at all; on the free-threaded build the three
that did move (
updateonCIMultiDict-0.24% and onMultiDict+0.08%,
popitemonCIMultiDict-0.02%) sit well inside the noisefloor the untouched pure-Python rows show across the same pair of
runs, which reaches 1.8%.
docs/benchmark.rstis unchangedaccordingly.
Related issue number
None; this follows #1552 directly.
Checklist
CONTRIBUTORS.txtCHANGES/foldermake doc-spellingpasses and any new technical words are added todocs/spelling_wordlist.txtAgent run details (optional, for reviewers)
Tests, each in its own virtualenv against its own copy of the tree, so
a stale
.socannot make a leg lie:Every leg with a C extension built the Cython harness too and ran with
MULTIDICT_TEST_REQUIRE_CYAPI=1, so the_testcyapihalf oftests/test_capi.pyis a hard failure rather than a skip.The
md_foreachharnesses now return(identity, hash, key, value),and the tests assert the hash against
hash(identity), which on aCIMultiDictis the lower-cased form's hash and not the key's.Lint:
pre-commit run --all-filespasses, includingclang-formatand both
mypyhooks.make doc-spellingpasses.Benchmarks:
benchmarks/callgrind_driver.py,PYTHONHASHSEED=0, onCPython 3.14.7 and 3.14.7t, base (pinned at the merge base cd92a6c)
and branch each built from a clean copy of its own tree in its own
virtualenv. Numbers in the section above.
Drafted with Claude Opus 5 in Claude Code. Left as a draft for @asvetlov to review before it goes out.