Repository navigation
gh-162782: Speed up set key comparison and hashing - #162783
Closed
josh-hurst wants to merge 1 commit into
Closed
josh-hurst wants to merge 1 commit into
josh-hurst wants to merge 1 commit into
Conversation
Compare exact compact integers and strings directly when probing a locked set or inserting a key. Reuse cached string and tuple hashes and compute compact integer hashes inline.
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.
Speed up set lookups by comparing exact compact integers and strings directly and by reusing cached hashes for strings and tuples and computing compact integer hashes inline.
Across five alternating pairs on macOS arm64 at
-O2, median base/patched ratios were 1.308× for integer membership, 1.278× for intersection, 1.327× for difference, and 2.027× for subset. Meteor measured 1.017×, within noise (two of five pairs were slower). Membership with Python-defined__hash__/__eq__measured 0.980×, the cost of the extra exact-type checks.Both debug builds passed the set suites and refleak checks. Free-threaded stress and ASan/UBSan also passed. The hash call sites may need a minor rebase with #161536.
Found and written by an AI optimization pipeline I run; I reviewed every line, ran the tests and sanitizers, and can answer for it.