Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup take_boolean / take_bits for non-null indices (~4 - 5x speedup) #2307

Merged
merged 1 commit into from Aug 4, 2022

Conversation

Dandandan
Copy link
Contributor

Which issue does this PR close?

Closes #2306

Rationale for this change

Speedup for (common) case of non-null indices array:

Benchmarking take bool 512: Collecting 100 samples in estimated 5.0003 s (6.8M i                                                                                take bool 512           time:   [733.01 ns 733.90 ns 735.34 ns]
                       change: [-76.500% -76.428% -76.358%] (p = 0.00 < 0.05)
                       Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
 3 (3.00%) high severe

Benchmarking take bool 1024: Collecting 100 samples in estimated 5.0004 s (3.9M                                                                                 take bool 1024          time:   [1.2751 µs 1.2767 µs 1.2786 µs]
                       change: [-79.428% -79.373% -79.309%] (p = 0.00 < 0.05)
                       Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
 1 (1.00%) high severe

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Aug 3, 2022
@Dandandan
Copy link
Contributor Author

FYI @jhorstmann this is just brining the special case back (I saw i was discussed a bit here #2064 (comment)). I think for now this might be the easy way forward while we work on making this work more generally.

@Dandandan Dandandan changed the title Speedup take_bits (~4 - 5x speedup) Speedup take_boolean / take_bits (~4 - 5x speedup) Aug 3, 2022
@Dandandan Dandandan changed the title Speedup take_boolean / take_bits (~4 - 5x speedup) Speedup take_boolean / take_bits for non-null indices (~4 - 5x speedup) Aug 3, 2022
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 looks very nice to me

.enumerate()
.try_for_each::<_, Result<()>>(|(i, index)| {
if let Some(index) = index {
let index = ToPrimitive::to_usize(&index).ok_or_else(|| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to figure out how to use https://docs.rs/arrow/19.0.0/arrow/datatypes/trait.ArrowNativeType.html#method.to_usize here to make the code slightly more pretty, but it wasn't obvious to me 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the pattern occurs quite often. Maybe we can at least reduce the amount of ok_or_else(|| {... by having this function available (so it becomes something like let index = ToPrimitive::to_usize_or_error(&index)?; everywhere?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps more rust like:

ToPrimitive::try_to_usize(&index)?

@Dandandan Dandandan merged commit 4b15b7e into apache:master Aug 4, 2022
@ursabot
Copy link

ursabot commented Aug 4, 2022

Benchmark runs are scheduled for baseline = d56d88e and contender = 4b15b7e. 4b15b7e is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize take_bits for non-null indices
4 participants