Skip to content

Drop ALWAYS_INLINE from three walk helpers - #1701

Merged
asvetlov merged 1 commit into
aio-libs:masterfrom
asvetlov:claude/remove-always-inline-walk-037ab7
Oct 6, 2026
Merged

asvetlov merged 1 commit into
aio-libs:masterfrom
asvetlov:claude/remove-always-inline-walk-037ab7

Conversation

@asvetlov

@asvetlov asvetlov commented Oct 6, 2026

Copy link
Copy Markdown
Member

What do these changes do?

Drops ALWAYS_INLINE from _md_walk_all_scan(), md_walk_all() and md_walk() in walk.h, and folds _md_seen_release() into md_walk_with_hash(), its only caller.

md_walk_with_hash() keeps its pin: out of line, the visitor call in getall becomes indirect. Callgrind on CIMultiDict.getall, Ir per call:

build master all four pins dropped this PR
GIL 3.14.7 860.3 929.3 (+8.0%) 860.3
FT 3.14.7t 875.8 931.6 (+6.4%) 874.8

With this PR, update moves +0.1-0.2% and every other operation stays within 1 Ir. A new tools/check_inlining.py rule keeps md_walk_with_hash() inline in the getall entry points; it fails when the pin is removed.

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

  • I think the code is well written
  • Unit tests for the changes exist (N/A, no behavior change; covered by the existing suite)
  • Documentation reflects the changes (N/A)
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt (N/A)
  • 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

Drafted with Claude Opus 5.5; reviewed by @asvetlov.

Agent run details (optional, for reviewers)

Tests: pytest -q on the C extension, 3.14.7 (4089 passed) and 3.14.7t (4074 passed), run on the all-pins-dropped variant; the final tree differs from it only by the restored pin. Pure-Python leg not run, since only C changed.
Inlining: tools/check_inlining.py ok on 3.14.7 (24 rules) and 3.14.7t (26 rules).
Perf: benchmarks/callgrind_driver.py --include-multidict-only --impl cimultidict_c against 70299d2.

Keep the pin on md_walk_with_hash(): out of line, getall's visitor
call becomes indirect and getall costs 6-8% more. A check_inlining.py
rule now guards it. Fold _md_seen_release() into its only caller.
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Oct 6, 2026
@asvetlov
asvetlov marked this pull request as ready for review October 6, 2026 11:15
@asvetlov
asvetlov requested a review from webknjaz as a code owner October 6, 2026 11:15
@codspeed

codspeed Bot commented Oct 6, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 706 untouched benchmarks


Comparing asvetlov:claude/remove-always-inline-walk-037ab7 (0fbb90a) with master (580c2f0)

Open in CodSpeed

@asvetlov
asvetlov merged commit 23b5497 into aio-libs:master Oct 6, 2026
53 checks passed
@asvetlov
asvetlov deleted the claude/remove-always-inline-walk-037ab7 branch October 6, 2026 11:40
asvetlov added a commit that referenced this pull request Oct 7, 2026
<!-- Thank you for your contribution! -->

## What do these changes do?

Drops `inline` from `_md_seen_test_and_add()` and `ALWAYS_INLINE static
inline` from `md_walk_with_hash()` in `walk.h`, leaving both plain
`static`, and removes the `md_walk_with_hash` rule from
`tools/check_inlining.py` that #1701 added.

GCC now keeps one out-of-line `md_walk_with_hash()` with
`_md_seen_test_and_add()` inlined into it, shared by `getall` and
`md_walk()`; `md_walk.constprop.0` goes away, and `md_get_all()`
(outlined in #1727) folds back into `multidict_getall()`. `.text`
shrinks by 2752 bytes on GIL and 1312 on FT.

The cost is the indirect visitor call #1701 measured. Callgrind against
`409f8d1a`, Ir per call:

| build | operation | MultiDict | CIMultiDict |
|---|---|---|---|
| GIL 3.14.7 | `getall` | 840.0 -> 875.8 (+4.3%) | 888.3 -> 926.1
(+4.3%) |
| GIL 3.14.7 | `getitem_istr` | +0.7% | unchanged |
| FT 3.14.7t | `getall` | 860.4 -> 883.2 (+2.7%) | 906.6 -> 928.8
(+2.4%) |
| FT 3.14.7t | `setitem_insert` | +1.4% | +2.2% |
| FT 3.14.7t | `delitem` | +1.1% | -1.9% |
| FT 3.14.7t | `setitem_replace` | -1.3% | -2.6% |
| FT 3.14.7t | `iter_keys` | -3.6% | -3.4% |
| FT 3.14.7t | `setitem_istr` | +0.6% | -3.3% |

Every other row moved by under 1%. The FT rows other than `getall` do
not reach the changed code; they move with the layout of the smaller
binary.

## 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, no behavior change)
- [x] Documentation reflects the changes (N/A)
- [ ] 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>

Measurement: `benchmarks/callgrind_driver.py --include-multidict-only
--impl {multidict_c,cimultidict_c}`, base and changed trees installed
into separate venvs per build.

Codegen: `tools/codegen_diff.py --ref 409f8d1` reports 120 of 320
functions differ on 3.14.7 and 140 of 324 on 3.14.7t; `multidict_getall`
59 -> 291 instructions on GIL with `md_get_all` folded in.

Tests: `pytest -q --no-cov` on 3.10.17 (4093 passed) and 3.14.7t (4074
passed). Pure-Python leg not run, no Python change.
`tools/check_inlining.py` passes on 3.14.7 and 3.14.7t (16 and 19
rules). Pre-commit and `make doc-spelling` pass.
</details>
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