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

Optimize performance of math::trunc (~2.5x faster) #12909

Merged
merged 2 commits into from
Oct 16, 2024

Conversation

tlm365
Copy link
Contributor

@tlm365 tlm365 commented Oct 13, 2024

Rationale for this change

Same idea as #12881. Using the unary/binary functions allow faster processing (most likely auto-vectorized code) by avoiding branching on nulls.

What changes are included in this PR?

  • Apply unary and binary
  • Add benchmark

Are these changes tested?

Existing testcases.

Are there any user-facing changes?

No.

**BENCHMARK RESULT
screenshot_2024-10-13_19-49-09

let num_array = num.as_primitive::<Float32Type>();
let precision_array = precision.as_primitive::<Int64Type>();
let result: PrimitiveArray<Float32Type> =
arrow_arith::arity::binary(num_array, precision_array, |x, y| {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the same function as this? https://docs.rs/arrow/latest/arrow/compute/fn.binary.html

If so you could remove the new dependency (although it is in the dependency closure anyway already)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@simonvandel Thanks so much for reviewing

Is this the same function as this? https://docs.rs/arrow/latest/arrow/compute/fn.binary.html

Oh, yes it is. Nice!

@tlm365 tlm365 changed the title Optimize performance of math::trunc (~2.5x faster) Optimize performance of math::trunc (~2.5x faster) Oct 13, 2024
@tlm365 tlm365 marked this pull request as ready for review October 13, 2024 18:06
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.

Thanks @tlm365 and @simonvandel

ColumnarValue::Scalar(Int64(Some(0))) => Ok(Arc::new(
make_function_scalar_inputs!(num, "num", Float64Array, { f64::trunc }),
) as ArrayRef),
ColumnarValue::Array(precision) => Ok(Arc::new(make_function_inputs2!(
Copy link
Member

Choose a reason for hiding this comment

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

I've broadened #12923 to cover this too

@alamb
Copy link
Contributor

alamb commented Oct 16, 2024

I merged up from main to resolve a conflict on this branch

@alamb
Copy link
Contributor

alamb commented Oct 16, 2024

🚀 thanks again

@alamb alamb merged commit caeabc1 into apache:main Oct 16, 2024
26 checks passed
@tlm365 tlm365 deleted the optimize-trunc branch November 10, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants