Repository navigation
Commit 45552bd
authored
Fold the hash chain walk into _md_update() (#1757)
<!-- Thank you for your contribution! -->
## What do these changes do?
`_md_update_replace()`, the walk of the hash chain for each `update()`
item, was a separate out-of-line function. The call, with eight
arguments and the callee-saved register spills around it, cost about 25
instructions per item. Its loops now live in `_md_update()` itself,
which goes on to add the key when the walk does not find it. `merge()`
and `extend()` do not use this path.
The pure-Python backend has no equivalent call and is unchanged.
## Are there changes in behavior for the user?
No.
## Is it a substantial burden for the maintainers to support this?
No; one function fewer.
## Related issue number
Follow-up to #1755.
## Checklist
- [x] I think the code is well written
- [ ] Unit tests for the changes exist N/A, no behaviour change; covered
by the existing update() tests
- [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>
Callgrind, `PYTHONHASHSEED=0`, per call with a 100-item argument (N=120
minus N=20 runs), base cfd8ea2, CPython 3.14.7 and 3.14.7t:
| case | GIL md / ci | FT md / ci |
| --- | --- | --- |
| update(dict), keys present | -10.2% / -9.3% | -8.0% / -7.0% |
| update(list), keys present | -9.1% / -8.5% | -6.5% / -5.8% |
| update(dict) into an empty multidict | -8.7% / -7.1% | -6.6% / -5.1% |
| update(dict), new keys into 100 | -7.9% / -6.9% | -6.0% / -4.9% |
| update(list) with duplicate keys | -6.9% / -6.2% | -5.1% / -4.3% |
| update(multidict) | -2.9..-4.3% | -1.8..-4.0% |
| merge(...) | 0.0% (-2.0% from a multidict) | 0.0..-0.4% |
Also tried, and rejected: skipping the per-batch `updated` bitmap when
the source cannot repeat a key (a same-class multidict without
duplicates, no keywords). That made `update(multidict)` 2-5% cheaper,
but every other source paid 1-4% more for the flag test.
Tests: full suite passes on the C extension (3.14.7 GIL, 3.14.7t FT,
3.10.17) and on pure Python (`MULTIDICT_NO_EXTENSIONS=1 pytest
--no-c-extensions` from a clean tree copy). `tools/check_inlining.py`
passes on 3.14.7 and 3.14.7t. `make doc-spelling` passes.
</details>1 parent 84c5412 commit 45552bd
2 files changed
Lines changed: 28 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
84 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
85 | 92 | | |
86 | 93 | | |
87 | 94 | | |
| |||
171 | 178 | | |
172 | 179 | | |
173 | 180 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
| 181 | + | |
| 182 | + | |
203 | 183 | | |
204 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
205 | 192 | | |
206 | 193 | | |
207 | 194 | | |
| |||
0 commit comments