Skip to content

[opt](expr) Speed up double serialization for CSV output - #65943

Draft
Mryange wants to merge 1 commit into
apache:masterfrom
Mryange:opt-csv-double-serialization
Draft

[opt](expr) Speed up double serialization for CSV output#65943
Mryange wants to merge 1 commit into
apache:masterfrom
Mryange:opt-csv-double-serialization

Conversation

@Mryange

@Mryange Mryange commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

CSV OUTFILE spends substantial CPU time converting FLOAT and DOUBLE values to strings.

Root cause: the CSV serialization path creates a temporary std::string for every floating-point value, while the formatter generates a fixed number of significant digits instead of using fmt's faster shortest-roundtrip path.

This change writes formatted values directly to BufferWritable and uses shortest-roundtrip formatting for finite FLOAT and DOUBLE values. In the 1 million row CSV test, the average export time decreased from 14.155 seconds to 8.951 seconds. The focused DOUBLE formatting benchmark improved from 91.656 ns/value to 37.827 ns/value.

Release note

FLOAT and DOUBLE string serialization now uses the shortest round-trip representation. NaN and Infinity spelling is unchanged.

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

### What problem does this PR solve?

Issue Number: close apache#27329

Problem Summary: CSV OUTFILE spends substantial CPU time converting floating-point values to strings. The serialization path also creates a temporary std::string for every FLOAT and DOUBLE value. Use fmt shortest-roundtrip formatting and write the formatted value directly to BufferWritable to reduce conversion and allocation overhead.

### Release note

FLOAT and DOUBLE string serialization now uses the shortest round-trip representation.

### Check List (For Author)

- Test: Manual test
    - RELEASE benchmark build and focused FmtDoubleToString benchmark
    - 1 million row CSV OUTFILE comparison
- Behavior changed: Yes. Finite FLOAT and DOUBLE values use shortest round-trip string formatting; NaN and Infinity spelling is unchanged.
- Does this need documentation: No.
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

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.

2 participants