Repository navigation
Keep view, iterator and init code off the inlining budget - #1614
Merged
Merged
Conversation
md_contains() loses its pret argument; the two view operators that need the stored key call a new out-of-line md_find_key(). Every view and iterator slot and every module-init helper is NOINLINE, and md_calc_identity() is ALWAYS_INLINE, which puts it back into getall() and md_contains() on free-threaded builds with GCC 13.
asvetlov
marked this pull request as ready for review
September 27, 2026 18:29
Contributor
|
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?
With GCC 13, which CI and CodSpeed build with,
md_calc_identity()fell out of line ingetall()andmd_contains()on free-threaded builds, andmd_contains()fell out ofkeys().isdisjoint()on regular ones (the two failures #1612 reports). This keeps code whose speed does not matter off GCC's inlining budget, and forces the one helper that does inline:md_contains()loses itspretargument. The keys view&and-operators, the only users of the stored key, call a newNOINLINE md_find_key()instead.multidict_views_init,multidict_iter_init,istr_init,htkeys_pools_init,pool_init,new_capsule), isNOINLINE.md_calc_identity()isALWAYS_INLINE.The pure-Python implementation has no equivalent and is unchanged.
Are there changes in behavior for the user?
No, only speed. Measured with callgrind on GCC 13, instructions per operation against master: free-threaded
del d[key]-7.9% (MultiDict) and -7.5% (CIMultiDict),key in d-3.8% and -6.1%,CIMultiDictd[key]-2.1%; regularupdate()-3.6% and -3.5%. The worst regressions are +0.9% on free-threadedMultiDict.update()and +0.5% to +0.8% on regularkey in d. Geomean over 52 cells: -0.28% regular, -0.66% free-threaded.Is it a substantial burden for the maintainers to support this?
No.
Related issue number
Related to #1612
Checklist
CONTRIBUTORS.txt(N/A)CHANGES/foldermake doc-spellingpasses and any new technical words are added todocs/spelling_wordlist.txtDrafted with Claude Code (Claude Opus 5.5); reviewed by @asvetlov.
Agent run details (optional, for reviewers)
Measurement:
benchmarks/callgrind_driver.py --include-multidict-only, bracketed,PYTHONHASHSEED=0, CPython 3.14.7 and 3.14.7t, extension built with GCC 13.5 (gcc:13image) and the interpreter's own CFLAGS plus thesetup.pyrelease flags.ALWAYS_INLINE md_calc_identityalone gives geomean -0.15% regular / -0.59% free-threaded; theNOINLINEchanges on top add regularupdate()-3% and free-threadedkey in d-2%.tools/check_inlining.pyfrom #1612: all rules pass on both builds with GCC 13 and GCC 15 (master fails two with GCC 13).Tests: C extension on 3.14.7 and 3.10.17, 2803 passed each; pure Python (
MULTIDICT_NO_EXTENSIONS=1,--no-c-extensions) on 3.14.7, 1324 passed. Free-threaded suite left to CI.Lint:
pre-commit runclean;make doc-spellingclean.