PERF: restore hash table pre-allocation in value_count#65027
Open
jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
Open
PERF: restore hash table pre-allocation in value_count#65027jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
Conversation
…bject dtypes The n // 10 pre-allocation introduced in pandas-dev#64543 causes expensive hash table resizes for float64 (and other non-object types), resulting in ~2x regression in Series.mode() for float dtype. Restore the v3.0 pre-allocation of n for non-object types while keeping n // 10 for object dtype. 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.
NB: motivated by an asv regression vs 3.0
Summary
kh_resize(table, n)for non-object dtypes invalue_count, reverting the inadvertent change ton // 10from PERF: Eliminate redundant kh_get calls in hashtable operations #64543n // 10pre-allocation causes expensive hash table resizes during insertion for float64 (whose hash function uses murmur2 + NaN handling), resulting in ~2x regression inSeries.mode()for float dtypen // 10as it was in v3.0Benchmark (float, N=100000)
n // 10(regressed)n(this PR)Test plan
pytest pandas/tests/test_algos.py— 494 passedpytest pandas/tests/base/test_value_counts.py pandas/tests/frame/methods/test_value_counts.py pandas/tests/series/methods/test_value_counts.py pandas/tests/frame/methods/test_duplicated.py pandas/tests/series/methods/test_duplicated.py— 301 passed🤖 Generated with Claude Code