Repository navigation
Document what istr keys are worth on a CIMultiDict - #1547
Merged
asvetlov merged 9 commits intoSep 24, 2026
Merged
Conversation
On the free-threaded build every lock-free reader that brings num_active_readers back to zero calls _md_drain_retired(), which without a second thread is every lookup. The first thing it does is a sequentially consistent exchange on md->retired, and that list is empty almost every time. Check the list with a relaxed load first and move the rest of the drain behind a call, so a lookup that has nothing to free pays one load rather than an out-of-line call and a read-modify-write. Nothing is stranded by the narrower window: a table retired after the load reads the same as one retired just after the exchange, and _md_retire() drains again once its push is visible. Instruction counts on CPython 3.14, free-threaded: `key in md` -10.6%, `md[key]` -7.9%, a missing `md.get(key)` -5.0%, and -8.1%, -6.2% and -3.3% for the CIMultiDict equivalents. No other benchmarked operation moves beyond the measurement's noise floor. The GIL build emits byte-identical code, confirmed with tools/codegen_diff.py.
The numbers on this page were collected before the retired-table drain change, and before aio-libs#1533 through aio-libs#1538 landed, so the refresh moves more cells than that change alone touches; the free-threaded read rows are the ones it accounts for.
The page already advised creating istr keys once and reusing them, but not how much it saves. Add the instruction counts next to the plain str equivalents, for both builds, and note that a key which is not already lower case saves more still.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1547 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 41 41
Lines 6974 7014 +40
Branches 606 610 +4
=========================================
+ Hits 6974 7014 +40
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
asvetlov
marked this pull request as ready for review
September 24, 2026 06:37
Contributor
|
This comment has been minimized.
This comment has been minimized.
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
asvetlov
commented
Sep 24, 2026
Takes master's copies of hashtable.h, atomic_helpers.h and the 1546 fragment: aio-libs#1546 landed there, so the copies this branch carried are redundant and master's also has aio-libs#1539, aio-libs#1549 and aio-libs#1550 on top.
aio-libs#1539, aio-libs#1549 and aio-libs#1550 landed since these were collected, and the add row moved most: 876 to 765 on the GIL build, 1,035 to 939 free-threaded. Also restore the note that d.add() starts from an empty mapping and inserts 200 keys. Without it the lead-in describes every row as running against a 200-key mapping, which is true of the other two but not of that one.
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
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?
The
istrsection already tells people to build their keys once andreuse them, but not what that buys. This adds the instruction counts,
for both builds, next to the plain
strequivalents, and points outthat a key which is not already lower case saves more still, since it
has to be copied into a lower-cased string whose hash is not cached.
Numbers come from
benchmarks/callgrind_driver.py --include-multidict-only,the same harness and machine as the tables in
docs/benchmark.rst.#1546 has landed, so this is down to its own two files. The figures were
re-measured against master afterwards, since #1539, #1549 and #1550 also
moved them;
d.add()shifted most, 876 to 765 on the GIL build.Are there changes in behavior for the user?
No, documentation only.
Is it a substantial burden for the maintainers to support this?
No, though the table joins
docs/benchmark.rstin needing a refreshwhen the figures move.
Related issue number
None.
Checklist
CONTRIBUTORS.txt— N/ACHANGES/foldermake doc-spellingpasses and any new technical words are added todocs/spelling_wordlist.txtDrafted with Claude Opus 5 in Claude Code; reviewed by @asvetlov.