Repository navigation
Commit b37f07c
authored
Allocate deferred decrefs in fixed-size blocks (#1501)
<!-- Thank you for your contribution! -->
## What do these changes do?
Replaces the storage of `md_deferred_decref_t` (free-threaded build
only) with a chain of fixed-size blocks. Each block holds 511 object
pointers (4 KiB with the pointer) plus a `next` pointer. The first block
is inline in the struct and is always the tail of the chain; when it
fills, a heap block is prepended, so every block behind the current one
is full and `md_deferred_decref_release()` needs no per-block counts.
This drops the old 8-slot inline array and its doubling
`PyMem_Realloc`/`memcpy` growth path.
The GIL build and the pure-Python implementation do not use this
structure and are unaffected.
## Are there changes in behavior for the user?
No.
## Is it a substantial burden for the maintainers to support this?
No; the init/push/release API is unchanged and the implementation is
shorter than the previous one.
## Related issue number
N/A
## Checklist
- [x] I think the code is well written
- [x] Unit tests for the changes exist
- [x] Documentation reflects the changes (N/A, internal only)
- [ ] 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); reviewed by @asvetlov.
<details>
<summary>Agent run details (optional, for reviewers)</summary>
New test `test_replace_many_duplicates_releases_all` replaces 3000
duplicates via `__setitem__` and `update()` (about 9000 deferred
decrefs, many heap blocks) and checks via weakrefs that every old value
is released. Temporarily breaking the release walk to skip full blocks
makes it fail on the C extension.
- 3.14t, `MULTIDICT_DEBUG_BUILD=1`: 2066 passed, 18 skipped
- 3.14t, debug + `MULTIDICT_ASAN_BUILD=1` (`-k "not test_leak"`, no
`PYTHONMALLOC=malloc` since free-threaded CPython rejects it): 2055
passed, no sanitizer reports
- 3.13 C extension: 2063 passed; `--no-c-extensions`: 1039 passed
- `make doc-spelling`, pre-commit: pass
- Benchmarks not compared locally.
</details>1 parent 563f667 commit b37f07c
3 files changed
Lines changed: 64 additions & 31 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 | |
|---|---|---|---|
| |||
1015 | 1015 | | |
1016 | 1016 | | |
1017 | 1017 | | |
1018 | | - | |
1019 | | - | |
1020 | | - | |
1021 | | - | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
1022 | 1028 | | |
1023 | 1029 | | |
1024 | | - | |
1025 | | - | |
| 1030 | + | |
1026 | 1031 | | |
1027 | | - | |
| 1032 | + | |
1028 | 1033 | | |
1029 | 1034 | | |
1030 | 1035 | | |
1031 | 1036 | | |
1032 | 1037 | | |
1033 | | - | |
| 1038 | + | |
| 1039 | + | |
1034 | 1040 | | |
1035 | | - | |
1036 | 1041 | | |
1037 | 1042 | | |
1038 | 1043 | | |
1039 | 1044 | | |
1040 | 1045 | | |
1041 | | - | |
1042 | | - | |
1043 | | - | |
1044 | | - | |
1045 | | - | |
1046 | | - | |
1047 | | - | |
1048 | | - | |
1049 | | - | |
1050 | | - | |
1051 | | - | |
1052 | | - | |
1053 | | - | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
1054 | 1049 | | |
1055 | 1050 | | |
1056 | 1051 | | |
1057 | | - | |
1058 | | - | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
1059 | 1055 | | |
1060 | 1056 | | |
1061 | 1057 | | |
| |||
1073 | 1069 | | |
1074 | 1070 | | |
1075 | 1071 | | |
1076 | | - | |
| 1072 | + | |
1077 | 1073 | | |
1078 | 1074 | | |
1079 | 1075 | | |
1080 | 1076 | | |
1081 | 1077 | | |
1082 | | - | |
| 1078 | + | |
1083 | 1079 | | |
1084 | 1080 | | |
1085 | 1081 | | |
1086 | 1082 | | |
1087 | 1083 | | |
1088 | 1084 | | |
1089 | | - | |
1090 | | - | |
1091 | | - | |
1092 | | - | |
1093 | | - | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
1094 | 1097 | | |
1095 | 1098 | | |
1096 | 1099 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2321 | 2321 | | |
2322 | 2322 | | |
2323 | 2323 | | |
| 2324 | + | |
| 2325 | + | |
| 2326 | + | |
| 2327 | + | |
| 2328 | + | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
| 2346 | + | |
| 2347 | + | |
| 2348 | + | |
| 2349 | + | |
2324 | 2350 | | |
2325 | 2351 | | |
2326 | 2352 | | |
| |||
0 commit comments