Skip to content

Make the bulk update helpers plain static functions - #1711

Merged
asvetlov merged 2 commits into
aio-libs:masterfrom
asvetlov:claude/multidict-static-functions-caec8c
Oct 6, 2026
Merged

asvetlov merged 2 commits into
aio-libs:masterfrom
asvetlov:claude/multidict-static-functions-caec8c

Conversation

@asvetlov

@asvetlov asvetlov commented Oct 6, 2026

Copy link
Copy Markdown
Member

What do these changes do?

Drops ALWAYS_INLINE static inline from _multidict_bulk() and _multidict_bulk_locked(), so __init__(), extend(), update() and merge() share one out-of-line copy instead of each compiling its own. _md_to_dict_scan() is folded into md_to_dict(), which now picks the entry kind at runtime instead of specializing a copy per kind. _multidict_clone_fast() was already plain static.

The _multidict_bulk rule in tools/check_inlining.py (#1591, "one shared copy made subclass init 7-8% slower") is removed: the bulk paths changed a lot since then, and the cost measured now is far smaller.

Callgrind, 3.14.7, instructions per operation, base vs this branch:

Operation GIL FT
reinit_items_small +1.1% to +1.5% +0.9% to +1.1%
to_dict(), 200 entries, 150 keys -0.7% to +0.9% -0.7% to +0.9%
every other row, ctor_* included under 0.5% under 0.5% (iter_items +2 Ir)

reinit_items_small is d.__init__(items) on an existing instance; construction itself goes through vectorcall and is unaffected.

Are there changes in behavior for the user?

No.

Is it a substantial burden for the maintainers to support this?

No, it removes code.

Related issue number

N/A

Checklist

  • I think the code is well written
  • Unit tests for the changes exist (N/A, no behaviour 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 Code (Claude Opus 5.5); to be reviewed by @asvetlov.

Agent run details (optional, for reviewers)

Tests: pytest -q passed on the C extension under 3.14.7 GIL (4089 passed), 3.14.7t FT (4074 passed) and 3.10 (4093 passed), and on the pure-Python build with --no-c-extensions (1610 passed).
Inlining: tools/check_inlining.py ok on 3.14.7 and 3.14.7t.
Measurement: benchmarks/callgrind_driver.py --include-multidict-only, base and branch trees in separate copies; to_dict() measured with a bracketed callgrind script (PYTHONHASHSEED=0, two loop counts differenced).

Drop ALWAYS_INLINE from _multidict_bulk() and _multidict_bulk_locked(),
fold _md_to_dict_scan() into md_to_dict() with a runtime kind, and
remove the _multidict_bulk inlining rule.
@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 15:20
@asvetlov
asvetlov requested a review from webknjaz as a code owner October 6, 2026 15:20
@codspeed

codspeed Bot commented Oct 6, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 706 untouched benchmarks


Comparing asvetlov:claude/multidict-static-functions-caec8c (cb675c8) with master (9224f77)

Open in CodSpeed

@asvetlov
asvetlov merged commit cf42e75 into aio-libs:master Oct 6, 2026
52 checks passed
@asvetlov
asvetlov deleted the claude/multidict-static-functions-caec8c branch October 6, 2026 15:36
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