perf(rust,python): avoid quadratic exclude
behaviour when selecting against dtypes and/or wildcards
#8953
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.
Closes #8947.
Huge speedup when excluding on wide frames; multiple orders of magnitude as the number of cols gets large. (Even though it's not noticeable on smaller frames, the quadratic behaviour really catches up with you as you head into the tens of thousands of columns 😅).
Changed
prepare_excluded
to return a HashSet as the number of items it can hold may be large, so we want theO(1)
lookup; thedtypes
param doesn't need the same treatment as even in the most extreme case there can only be a handful of them. Also moved the exclusion-match (insideexpand_dtypes
) up into the iter_fields filter.Example
Results
Timings:
Hardware: Apple Silicon M2 Max Pro
Compiled with:
maturin develop --release -- -C target-cpu=native
Plot:
Orange: current
main
.Blue: this
pr
.