Repository navigation
Merge the bodies of __init__(), extend(), update() and merge() - #1673
Merged
Merged
Conversation
The four entry points were copies of the same three locking arms. One ALWAYS_INLINE helper takes the operation as a constant, so each entry point still compiles its own copy. md_post_update() goes out of line: inlined into update(), it took Py_NewRef() out of the free-threaded items iterator.
asvetlov
marked this pull request as ready for review
October 4, 2026 13:41
Contributor
|
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?
__init__(),extend(),update()andmerge()in_multidict.cwere four copies of the same structure: parse the arguments, pick one of three locking arms by the type of the source, run the batch, flush the watchers. They now share_multidict_bulk()and_multidict_bulk_locked(), which removes about 140 lines from_multidict.c.Both helpers are
ALWAYS_INLINEand take the operation as a constant, so every entry point still compiles its own copy, as thecheck_inlining.pyrule from #1591 requires; the rule now names_multidict_bulk.md_post_update()moves out of line. Left to GCC it was inlined into one arm ofupdate(), and on free-threaded builds that tookPy_NewRef()out of the items iterator (+5 instructions per step) andlist_getitem_ref()out of the constructor loop. There is no way to express aNOINLINEpin as a rule incheck_inlining.py, so the comment on the function carries the reason.No behaviour change. The pure-Python implementation is not affected.
Measured with callgrind, before and after, on 3.14.7 and 3.14.7t, both classes:
benchmarks/callgrind_driver.py --include-multidict-only: every row within 0.06%.merge()is the consistent mover, about +0.1% to +0.2% (roughly 20 to 30 instructions per call) for the call tomd_post_update().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
CONTRIBUTORS.txt(N/A)CHANGES/foldermake doc-spellingpasses and any new technical words are added todocs/spelling_wordlist.txtDrafted with Claude Code (Claude Fable 5.1); not yet reviewed by a human.
Agent run details (optional, for reviewers)
All numbers are from the branch rebased onto cfcf7f3.
tools/codegen_diff.pyis not empty for this change (30 functions on 3.14.7 and 184 on 3.14.7t before the rebase), which is why it was measured instead.multidict_items_iter_tp_iternext,_md_update_from_seq_extend_ci/cs,md_del_ci/cson 3.14.7t are the same as on the base; withoutNOINLINEonmd_post_update()they differ.tools/check_inlining.pyon 3.14.7 and 3.14.7t: ok--no-c-extensions: 1604 passedMULTIDICT_DEBUG_BUILD=1 MULTIDICT_ASAN_BUILD=1, 3.14.7,PYTHONMALLOC=malloc,-k "not test_leak": 4065 passedmake doc-spellingand pre-commit: passNot run: the
MULTIDICT_NO_FREELIST=1ASan pass, TSan, wall-clock benchmarks.