Skip to content

perf: optimize spark_cast_float64_to_utf8 (~40% faster)#4918

Open
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:auto-opt/spark_cast_float64_to_utf8-datafusion-comet-20260714-045616
Open

perf: optimize spark_cast_float64_to_utf8 (~40% faster)#4918
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:auto-opt/spark_cast_float64_to_utf8-datafusion-comet-20260714-045616

Conversation

@andygrove

@andygrove andygrove commented Jul 14, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

N/A

Rationale for this change

Optimize existing expression.

What changes are included in this PR?

Format float-to-string casts straight into a GenericStringBuilder with a reused scratch buffer instead of allocating a String per row (and a second one in the scientific-notation path), removing one malloc/free and one copy per value.

How are these changes tested?

Existing tests.

Benchmark (criterion):

  • cast_f32_to_utf8: 42.453% faster (base 408097ns -> cand 234847ns)
  • cast_f64_to_utf8: 41.57% faster (base 418096ns -> cand 244294ns)

Full criterion output:

cast_float_to_string/cast_f64_to_utf8
                        time:   [243.85 µs 244.03 µs 244.23 µs]
                        change: [−41.767% −41.570% −41.425%] (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
cast_float_to_string/cast_f32_to_utf8
                        time:   [234.71 µs 234.86 µs 235.08 µs]
                        change: [−42.515% −42.453% −42.390%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  2 (2.00%) low mild
  1 (1.00%) high mild
  3 (3.00%) high severe

@andygrove andygrove changed the title perf: optimize spark_cast_float64_to_utf8 in datafusion-comet-spark-expr perf: optimize spark_cast_float64_to_utf8 (~40% faster) Jul 14, 2026
@andygrove andygrove marked this pull request as ready for review July 14, 2026 14:42
@andygrove andygrove requested a review from coderfender July 14, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant