Our great sponsors
-
A little over 2 years ago, I posted about making Rust float parsing fast and correct. Due to personal reasons, I needed a break prior to merging improvements into the Rust core library. In that time, major improvements to float parsing have been developed, further improving upon anything I had done. And, as of today, these changes have been merged into the core library.
-
JSON is an interesting example, since the syntax of valid floats is slightly different than what Rust expects. Luckily, I'm the author of a minimal, and am also the author of a PR to bring this to fast-float-rust.
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
-
fast_float
Fast and exact implementation of the C++ from_chars functions for number types: 4x to 10x faster than strtod, part of GCC 12 and WebKit/Safari
Daniel Lemire @lemire (creator of the algorithm, author of the C++ implementation, and provided constant feedback to help guide the PR).
-
So, what about safety? fast-float-rust uses unsafe code fairly liberally, so how do the merged changes fix that? Well, all unsafe code except when needed was removed, and it was shown to have no impact on performance or even assembly generation. In fact, the generated assembly is slightly better in some cases. Every call to an unsafe function can be trivially shown to be correct, and all but 1 call has the following format:
-
If you're interested, I've basically compiled a list of all the different float formats from over 50 programming and data interchange formats.
-
No, libcore uses simple branching code at the moment, see https://github.com/rust-lang/rust/issues/68455. The issue is still actively being worked on. Note, it's not a simple drop in, and there seem to be even faster algorithms. For now there is https://github.com/rusticstuff/simdutf8.