Skip to content

perf: optimize log in datafusion-functions#23546

Draft
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:auto-opt/log-datafusion-20260713-212805
Draft

perf: optimize log in datafusion-functions#23546
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:auto-opt/log-datafusion-20260713-212805

Conversation

@andygrove

Copy link
Copy Markdown
Member

This PR was created by an LLM as a draft PR. I will mark it as ready for review after human review.

Which issue does this PR close?

N/A — autonomous exploratory PR.

Rationale for this change

Hoist the scalar base's natural logarithm out of the per-row loop in log(base, x), since f64::log(base) is ln(x)/ln(base) and recomputed ln(base) on every row, halving the transcendental calls with bit-identical results.

What changes are included in this PR?

Hoist the scalar base's natural logarithm out of the per-row loop in log(base, x), since f64::log(base) is ln(x)/ln(base) and recomputed ln(base) on every row, halving the transcendental calls with bit-identical results.

Are these changes tested?

Correctness: unit tests + seeded differential fuzz (bit-identical Arrow output vs main).

Benchmark (criterion):

  • log_f64_array_base: 3.204% faster (base 37537ns -> cand 36335ns)
  • log_f32_scalar_base: -0.358% faster (base 13815ns -> cand 13865ns)
  • log_f64_default_base: 6.02% faster (base 18314ns -> cand 17211ns)
  • log_f32_array_base: -0.329% faster (base 24782ns -> cand 24863ns)
  • log_f64_scalar_base: 6.153% faster (base 18284ns -> cand 17159ns)

Full criterion output:

log_f64_default_base    time:   [17.193 µs 17.203 µs 17.220 µs]
                        change: [−6.1581% −6.0197% −5.9020%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 4 outliers among 100 measurements (4.00%)
  2 (2.00%) high mild
  2 (2.00%) high severe

log_f64_scalar_base     time:   [17.140 µs 17.146 µs 17.152 µs]
                        change: [−6.2343% −6.1533% −6.0954%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe

log_f32_scalar_base     time:   [13.859 µs 13.867 µs 13.877 µs]
                        change: [+0.2720% +0.3581% +0.4457%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 8 outliers among 100 measurements (8.00%)
  1 (1.00%) low mild
  3 (3.00%) high mild
  4 (4.00%) high severe

log_f64_array_base      time:   [36.240 µs 36.363 µs 36.489 µs]
                        change: [−3.3640% −3.2036% −3.0253%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 10 outliers among 100 measurements (10.00%)
  10 (10.00%) high mild

log_f32_array_base      time:   [24.855 µs 24.868 µs 24.892 µs]
                        change: [+0.2349% +0.3285% +0.4056%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 9 outliers among 100 measurements (9.00%)
  2 (2.00%) low mild
  3 (3.00%) high mild
  4 (4.00%) high severe

Are there any user-facing changes?

@github-actions github-actions Bot added the functions Changes to functions implementation label Jul 14, 2026
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.

1 participant