Repository navigation
Always inline the hash-table probe initializer - #1554
Merged
asvetlov merged 2 commits intoSep 24, 2026
Merged
Conversation
GCC emits it out of line otherwise, so every probe in the extension opens with a call for five stores.
asvetlov
force-pushed
the
claude/htkeysiter-init-inline
branch
from
September 24, 2026 06:58
1f0a982 to
442570f
Compare
Contributor
|
| static inline void | ||
| /* Always inlined: left to itself GCC emits it out of line, and then | ||
| every probe in the extension opens with a call for five stores. */ | ||
| ALWAYS_INLINE static inline void |
Contributor
There was a problem hiding this comment.
Forcing the probe initializer inline changes a performance-sensitive path, but the published instruction-count tables in docs/benchmark.rst remain unchanged despite the reported improvement of up to 8.8%. This violates the repository directive to refresh those tables when an operation moves by more than a couple of percent. Update the affected rows before merging so readers are not given stale comparisons.
Context Used: AGENTS.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
4 of 6 tasks
asvetlov
added a commit
that referenced
this pull request
Sep 28, 2026
<!-- Thank you for your contribution! --> ## What do these changes do? Adds `tools/check_inlining.py` and an `Inlining` CI job on 3.14 and 3.14t. The script compiles `_multidict.c` with the interpreter's flags plus the release flags from `setup.py`, disassembles it, and fails when an entry point a rule names (a slot, method or `MultiDict_*` C API function) reaches the rule's helper through any chain of out-of-line calls; the report shows the chain. The first rules come from the regressions in #1527, #1530, #1541, #1542, #1554, #1591 and #1604, each of which slowed a benchmark on code the change never touched. AGENTS.md now asks agents to run it, to add a rule whenever they fix an inlining regression or pin a helper, and never to weaken a rule without a measurement. CI builds with GCC 13.3. The two rules it failed on master at first (`md_calc_identity` out of line in `getall()` and `popall()` on free-threaded builds) were fixed by #1614; master now passes every rule with GCC 13 and GCC 15 on both builds. ## Are there changes in behavior for the user? No. ## Is it a substantial burden for the maintainers to support this? No. A PR that moves an inlining decision on purpose edits the matching rule. ## Related issue number N/A ## Checklist - [x] I think the code is well written - [ ] Unit tests for the changes exist (N/A, a CI-only tool; verified by reintroducing past regressions, see below) - [x] Documentation reflects the changes - [ ] If you provide code modification, please add yourself to `CONTRIBUTORS.txt` (N/A) - [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 Code (Claude Opus 5.5); reviewed by @asvetlov. <details> <summary>Agent run details (optional, for reviewers)</summary> Master passes on 3.14.7 and 3.14.7t with GCC 14 and GCC 15. Each past regression reintroduced by hand was caught: - dropping `ALWAYS_INLINE` from `htkeysiter_init`: out-of-line copy reported, plus `md_contains` out of `isdisjoint` - dropping `NOINLINE` from the view, iterator and shell pool helpers (#1541/#1542): `md_contains` out of `isdisjoint` - dropping `NOINLINE` from `_ci_str_to_identity` (#1527): failures across getitem, getall, replace and `isdisjoint` on both builds GCC 13.5 (`gcc:13` Docker image): the two failures listed above. Lint: `pre-commit run` clean; `make doc-spelling` clean. </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?
htkeysiter_init()sets five fields of the struct that walks a hashchain, and every lookup, insertion and deletion in the extension starts
by calling it. GCC was emitting it out of line, so each of those paths
opened with a call. Marking it
ALWAYS_INLINEremoves the call.Instructions per operation on a GIL build of CPython 3.13, measured with
benchmarks/callgrind_driver.pyagainst3336132:MultiDictCIMultiDictfor k, v in d.items()d.setdefault(key, v), new keyd.get(key), missd.pop(key)d.update(other)d[key] = v, existing keyd.getall(key)d.popitem()Nothing measured slower on either class. Free-threaded builds already
inlined it:
tools/codegen_diff.pyreports the emitted code byte forbyte identical there, so the change is a no-op on that build.
Are there changes in behavior for the user?
No, other than the speed. The function's body is untouched.
Is it a substantial burden for the maintainers to support this?
No. It is one attribute, next to the existing
ALWAYS_INLINEonmd_calc_identity_hash()and for the same reason.Related issue number
None.
Checklist
CONTRIBUTORS.txt— N/A, already listedCHANGES/foldermake doc-spellingpasses and any new technical words are added todocs/spelling_wordlist.txtAgent run details (optional, for reviewers)
Tests, all against this branch:
MULTIDICT_NO_EXTENSIONS=1, 3.13.2: 1243 passed, 17 skippedCodegen:
tools/codegen_diff.py --ref upstream/masterreports 109 of 200functions differing on 3.13 with
htkeysiter_initgone as a standalonesymbol, and 0 of 203 on 3.14.7t.
Measurements are deterministic instruction counts under Callgrind with
PYTHONHASHSEED=0; two runs of the same build agreed on all 20 cells.Drafted with Claude Opus 5; reviewed by @asvetlov.