You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "kumarUjjawal (via GitHub)" <gi...@apache.org> on 2026/01/11 16:34:13 UTC
[PR] perf: Optimize floor and ceil scalar performance [datafusion]
kumarUjjawal opened a new pull request, #19752:
URL: https://github.com/apache/datafusion/pull/19752
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
- Part of https://github.com/apache/datafusion-comet/issues/2986
## Rationale for this change
- The current floor and ceil implementations always convert scalar inputs to arrays via `values_to_arrays()`, which introduces unnecessary overhead when processing single values.
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
## What changes are included in this PR?
- Add scalar fast path for floor and ceil
- Add criterion benchmark for floor/ceil to measure performance
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
## Are these changes tested?
- All sqllogictest pass
- Addec benchmark
| Benchmark | Array Time | Scalar Time | Speedup |
|---------------------|------------|-------------|---------|
| floor_f64 (1024) | ~396 ns | ~147 ns | 2.7× |
| ceil_f64 (1024) | ~363 ns | ~150 ns | 2.4× |
| floor_f64 (4096) | ~681 ns | ~144 ns | 4.7× |
| ceil_f64 (4096) | ~667 ns | ~144 ns | 4.6× |
| floor_f64 (8192) | ~1,638 ns | ~144 ns | 11.4× |
| ceil_f64 (8192) | ~1,634 ns | ~144 ns | 11.3× |
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
## Are there any user-facing changes?
No
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Optimize floor and ceil scalar performance [datafusion]
Posted by "kumarUjjawal (via GitHub)" <gi...@apache.org>.
kumarUjjawal commented on code in PR #19752:
URL: https://github.com/apache/datafusion/pull/19752#discussion_r2680822239
##########
datafusion/functions/src/math/ceil.rs:
##########
@@ -95,6 +95,31 @@ impl ScalarUDFImpl for CeilFunc {
}
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
+ let arg = &args.args[0];
+
+ // Scalar fast path for float types - avoid array conversion overhead
+ // Note: Decimal types use the array path for proper precision/overflow validation
+ if let ColumnarValue::Scalar(scalar) = arg {
+ match scalar {
+ ScalarValue::Float64(v) => {
+ return Ok(ColumnarValue::Scalar(ScalarValue::Float64(
+ v.map(f64::ceil),
+ )));
+ }
+ ScalarValue::Float32(v) => {
+ return Ok(ColumnarValue::Scalar(ScalarValue::Float32(
+ v.map(f32::ceil),
+ )));
+ }
+ ScalarValue::Null => {
+ return Ok(ColumnarValue::Scalar(ScalarValue::Float64(None)));
+ }
+ // Decimal types fall through to array path for overflow validation
Review Comment:
Thanks for the feedback.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Optimize floor and ceil scalar performance [datafusion]
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on code in PR #19752:
URL: https://github.com/apache/datafusion/pull/19752#discussion_r2680507437
##########
datafusion/functions/src/math/ceil.rs:
##########
@@ -95,6 +95,31 @@ impl ScalarUDFImpl for CeilFunc {
}
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
+ let arg = &args.args[0];
+
+ // Scalar fast path for float types - avoid array conversion overhead
+ // Note: Decimal types use the array path for proper precision/overflow validation
+ if let ColumnarValue::Scalar(scalar) = arg {
+ match scalar {
+ ScalarValue::Float64(v) => {
+ return Ok(ColumnarValue::Scalar(ScalarValue::Float64(
+ v.map(f64::ceil),
+ )));
+ }
+ ScalarValue::Float32(v) => {
+ return Ok(ColumnarValue::Scalar(ScalarValue::Float32(
+ v.map(f32::ceil),
+ )));
+ }
+ ScalarValue::Null => {
+ return Ok(ColumnarValue::Scalar(ScalarValue::Float64(None)));
+ }
+ // Decimal types fall through to array path for overflow validation
Review Comment:
For decimals, we could turn the scalars in arrays of size 1, pass through the existing code, then recreate a scalar from the resultant array, to benefit from code reuse and ensure we don't expand the array.
Not the cleanest way to do it but certainly the easiest.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Optimize floor and ceil scalar performance [datafusion]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead merged PR #19752:
URL: https://github.com/apache/datafusion/pull/19752
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org