73 points · by vitaut · 6y ago · 56 comments
edit: also, ~2.5KB of that is due to padding in power_of_ten_components. I wonder if it'd be better to split the uint64_t field into two uint32_ts to avoid this.
[1] https://github.com/lemire/fast_double_parser/blob/master/inc... [2] https://news.ycombinator.com/item?id=22440894 [3] https://en.wikichip.org/wiki/amd/ryzen_embedded/r1606g
And like anything, it depends on what you're doing. If you're doing lots of server-to-server RPCs on big distributed systems like within Google, it's much more reasonable to start with protobuf or the like than with JSON. And not just for performance reasons; having the generated code helps a lot with maintainability. (Some JSON libraries have something similar; some don't.)
Err, surely it should be equal to 10,000,000,000. Or more probably, they meant to write "1.0e1".
But the reality is the core of the algorithm is still a while loop that looks at each digit one at a time and multiplies by 10 each time ...
Very cool btw
Source: I regularly optimise C++ code in LibreOffice.
It looks like Rust is doing well on this. HashMap (the one everybody uses) is essentially a clone of Google's heavily-optimized C++ hash table:
https://abseil.io/blog/20180927-swisstables
... and if you need the collection to be sorted, their BTreeMap has much lower overhead than the C++ std::map, plus a big prominent note in its documentation saying that HashMap is usually the one you want.
I'm impressed. (Haven't looked at Zig yet.)
[0]: http://dtrace.org/blogs/bmc/2018/09/28/the-relative-performa...
That said, I've never seen strtod showing up in my profiles, but I bet if I was profiling web browsers then I would see it.
Jeroen van der Zijp, developer of the lesser known FOX Toolkit, claims to have done better than the Ryu algorithm. From his changelist [0]:
> New, faster, and often more accurate floating point to string conversion. No, this is not based on Ryu paper. New method reliably generates 16 digits, and does much better rounding.
I believe this [1] is his implementation in C++. See also his paper [2]. (I believe it's not peer-reviewed, but it does appear in Google Scholar.)
[0] http://www.fox-toolkit.org/
[1] https://github.com/gogglesguy/fox/blob/77396c638c1c4e05/lib/...
[2] http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf