Skip to content

perf: optimize round expression#23471

Merged
andygrove merged 2 commits into
apache:mainfrom
andygrove:auto-opt/round-datafusion-20260710-185523
Jul 14, 2026
Merged

perf: optimize round expression#23471
andygrove merged 2 commits into
apache:mainfrom
andygrove:auto-opt/round-datafusion-20260710-185523

Conversation

@andygrove

@andygrove andygrove commented Jul 11, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

N/A

Rationale for this change

Optimize an existing function

What changes are included in this PR?

round() over a no-null float column with scalar decimal_places now hoists the 10^dp factor out of the loop and uses the vectorizable infallible unary kernel instead of per-element try_unary+powi, with a fallback preserving bit-identical output for null/array cases.

Are these changes tested?

Existing tests

Benchmark (criterion):

  • 8192: 28.689% faster (base 2711ns -> cand 1933ns)
  • 4096: 41.544% faster (base 1382ns -> cand 808ns)
  • 1024: 25.253% faster (base 451ns -> cand 337ns)
  • 8192: 44.103% faster (base 1486ns -> cand 831ns)
  • 4096: 29.01% faster (base 679ns -> cand 482ns)
  • 1024: 20.457% faster (base 291ns -> cand 231ns)

Are there any user-facing changes?

No

@github-actions github-actions Bot added the functions Changes to functions implementation label Jul 11, 2026
@andygrove andygrove marked this pull request as ready for review July 11, 2026 01:51
Comment thread datafusion/functions/src/math/round.rs Outdated
Comment on lines +877 to +880
/// compiler can autovectorize. Requiring no null slots keeps the output
/// bit-identical to the fallible kernel: `unary` writes a computed value into
/// every slot while `try_unary` leaves null slots zeroed, so the two only agree
/// when there are no null slots. Returns `Ok(None)` when the fast path does not

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i feel we dont need to aim for this bit-identical approach? we can still apply this fast path even if there are nulls since the nulls should be masked anyway

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point. Thanks, I fixed that.

@andygrove andygrove changed the title perf: optimize round in datafusion-functions perf: optimize round expression Jul 13, 2026
Nulls are carried through by the unary kernel's null buffer, so the fast
path does not need to bail out on null slots.
@andygrove andygrove added this pull request to the merge queue Jul 14, 2026
@andygrove

Copy link
Copy Markdown
Member Author

Thanks for the review @Jefffrey

Merged via the queue into apache:main with commit 870f257 Jul 14, 2026
38 checks passed
@andygrove andygrove deleted the auto-opt/round-datafusion-20260710-185523 branch July 14, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants