Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve float to string cast by ~20%-40% #5401

Merged
merged 2 commits into from
Feb 18, 2024
Merged

Conversation

psvri
Copy link
Contributor

@psvri psvri commented Feb 15, 2024

Which issue does this PR close?

Closes #.

Rationale for this change

We can use ryu crate to cast floats to string for better performance. Ryu is used in crates like csv and serde-json for fast float to string conversion.

What changes are included in this PR?

I am using ryu to cast floats to string. The perf numbers are as below

cast f32 to string 512  time:   [18.055 µs 18.458 µs 18.932 µs]
                        change: [-26.059% -24.296% -22.401%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 14 outliers among 100 measurements (14.00%)
  8 (8.00%) high mild
  6 (6.00%) high severe

cast f64 to string 512  time:   [20.884 µs 21.154 µs 21.470 µs]
                        change: [-42.782% -41.722% -40.605%] (p = 0.00 < 0.05)
                        Performance has improved.

Are there any user-facing changes?

No

@github-actions github-actions bot added the arrow Changes to the arrow crate label Feb 15, 2024
@psvri
Copy link
Contributor Author

psvri commented Feb 15, 2024

Let me know if I need to create an issue for the PR.

@jhorstmann
Copy link
Contributor

Nice! I thought I benchmarked lexical vs ryu some time ago and did not see an improvement, but I can reproduce a 12% to 22% improvement here. 🚀

@psvri
Copy link
Contributor Author

psvri commented Feb 16, 2024

I experimented with iota crate as well for ints to string casts, but I didnt see any performance improvement when compared to lexical.

Copy link
Contributor

@Jefffrey Jefffrey left a comment

Choose a reason for hiding this comment

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

Nice 🚀

@Jefffrey Jefffrey merged commit 1a880d6 into apache:master Feb 18, 2024
26 checks passed
@psvri psvri deleted the cast_speedup branch February 18, 2024 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants