Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upInvestigate the Ryū algorithm for a simpler/faster implementation of float -> string conversion #52811
Comments
bstrie
added
the
T-compiler
label
Jul 28, 2018
This comment has been minimized.
This comment has been minimized.
|
cc @dtolnay in case this is of interest for serde |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
The repository can be found at https://github.com/ulfjack/ryu and the paper at https://dl.acm.org/citation.cfm?id=3192369. |
This comment has been minimized.
This comment has been minimized.
|
I did a line-by-line translation of the C implementation to unsafe Rust in https://github.com/dtolnay/ryu. It performs better than dtoa on some inputs but the output is less human readable. For example dtoa and serde_json prefer to print 0.3 as
Benchmark commit: dtolnay/dtoa@655152b |
This comment has been minimized.
This comment has been minimized.
matthieu-m
commented
Jul 29, 2018
|
@dtolnay : I would imagine that changing the output format would be trivial, no? On the other hand, the fact that it performs worse on |
This comment has been minimized.
This comment has been minimized.
|
As I understand it, the fact that short numbers perform worse is an inherent aspect of the algorithm. Dtoa goes left to right and avoids generating too many noise digits, so the performance is better on short numbers as reflected in the table. Ryū generates an exact representation and then goes right to left removing noise digits, so the performance is better on the longest numbers. The Ryū benchmarks all focus on a random distribution of numbers, and those have on average a lot of digits. |
This comment has been minimized.
This comment has been minimized.
matthieu-m
commented
Jul 29, 2018
Thank you for confirming my suspicion.
I would guess that whether the number of digits is random, or not, varies by application. This makes it quite difficult to pick one algorithm or the other. |
This comment has been minimized.
This comment has been minimized.
|
Ryū is seems to be slower in a few case versus What trade-off does
From what I understand, both Ryū and the |
nagisa
added
I-slow
T-libs
and removed
T-compiler
labels
Jul 30, 2018
This comment has been minimized.
This comment has been minimized.
|
Retagging as T-libs, T-compiler hardly has anything to do with libstd matters. |
bmahler
referenced this issue
Jul 31, 2018
Open
Consider adopting Ryu for faster floating point to string conversion. #1332
This comment has been minimized.
This comment has been minimized.
|
I switched from |
bstrie commentedJul 28, 2018
There's a new paper making the rounds on the topic of converting floats to their decimal string representations that claims to be both simpler and faster than prior algorithms: https://pldi18.sigplan.org/event/pldi-2018-papers-ry-fast-float-to-string-conversion . I'm particularly interested in the simplicity aspect, since I recall some old conversations regarding our current machinery for this being somewhat subtle and complicated (for speed purposes, I imagine). If we could drastically simplify the implementation without sacrificing speed, that might be a win. Good student or intern project, methinks.
(Apologies for how wishlisty this issue is, I've no clue who might be the presiding expert on our current float->string implementation.)