Feature or enhancement
Summary
delitem_common() currently calls lookdict_index() before checking whether the dictionary is combined or split.
For split dictionaries, the returned hash-table slot is not used. Therefore, the probe performed by lookdict_index() is redundant for split-table deletions.
I propose moving lookdict_index() into the combined-table branch avoiding a full probe sequence for every deletion from a split dictionary.
Benchmark
Measured with a free-threaded build, -Og, without PGO. The benchmark deletes keys from materialized instance dictionaries; medians over 12 alternating runs:
before after change
del d[k] 71.2 69.2 ns/op -2.8%
d.pop(k) 98.9 96.1 ns/op -2.8%
colliding hashes 78.0 74.4 ns/op -4.6%
Combined-table deletions are unchanged.
Clang also does not sink the lookdict_index() call into the branch at -O3 -DNDEBUG, so the improvement is not specific to the local -Og build.
Validation
The following test modules pass:
- test_dict
- test_dictviews
- test_dictcomps
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
Feature or enhancement
Summary
delitem_common()currently callslookdict_index()before checking whether the dictionary is combined or split.For split dictionaries, the returned hash-table slot is not used. Therefore, the probe performed by
lookdict_index()is redundant for split-table deletions.I propose moving
lookdict_index()into the combined-table branch avoiding a full probe sequence for every deletion from a split dictionary.Benchmark
Measured with a free-threaded build, -Og, without PGO. The benchmark deletes keys from materialized instance dictionaries; medians over 12 alternating runs:
Combined-table deletions are unchanged.
Clang also does not sink the
lookdict_index()call into the branch at -O3 -DNDEBUG, so the improvement is not specific to the local -Og build.Validation
The following test modules pass:
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs