gh-153198 Optimize set and frozenset membership lookup#153199
gh-153198 Optimize set and frozenset membership lookup#153199rajat315315 wants to merge 3 commits into
Conversation
…t-path for identical Unicode keys
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
StanFromIreland
left a comment
There was a problem hiding this comment.
Please provide benchmarks, run on a PGO + LTO build.
| #define PERTURB_SHIFT 5 | ||
|
|
||
| static int | ||
| static inline Py_ALWAYS_INLINE int |
There was a problem hiding this comment.
Is the compiler not already specialising this?
|
|
||
| // This is similar to set_compare_entry_lock_held() but we don't need to | ||
| // incref startkey before comparing and we don't need to check if the set has | ||
| // changed. This also omits the PyUnicode_CheckExact() special case since it |
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Linked Issue
Fixes gh-153198
Proposed Changes
Objects/setobject.cto:PyUnicode_CheckExactandunicode_eq()fast-path check inset_compare_frozenset.set_do_lookupasstatic inline Py_ALWAYS_INLINE intso the compiler can specialize and inline the lookup loop for both comparison target functions.test_set(all 644 tests passed successfully).Benchmarks (1,000,000 lookup operations)
set_lookup(int keys): 20.1% faster (reduced from 42.2 ms to 33.7 ms)set_lookup_str(string keys): 26.2% faster (reduced from 71.1 ms to 52.5 ms)frozenset_lookup_str(string keys): 17.0% faster (reduced from 71.2 ms to 59.1 ms)