Skip to content

Skip useless hash table probe when deleting from split dicts #158816

Description

@hetaozdh

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

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions