PERF: restore kh_get before kh_put in hashtable operations#65026
Open
jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
Open
PERF: restore kh_get before kh_put in hashtable operations#65026jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
Conversation
Partially reverts pandas-dev#64543, which replaced kh_get + kh_put with kh_put alone. While kh_put avoids a redundant hash for new keys, it is more expensive than kh_get for existing keys due to extra branching (resize checks, deleted-slot tracking). For low-cardinality data (e.g. boolean with 2 unique values), nearly all lookups hit existing keys, causing ~80% regression at the Cython level. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
kh_get+kh_putwithkh_putalone in the hashtable_unique,get_labels_groupby,value_count, andduplicatedmethodskh_putavoids a redundant hash for new keys, it is more expensive thankh_getfor existing keys due to extra branching in khash (resize checks, deleted-slot tracking)Factorize.time_factorizeat the Cython levelTest plan
test_algos.pyandtest_hashtable.pytests passalgorithms.Factorize.time_factorizefor boolean dtype matches v3.0 performance🤖 Generated with Claude Code