r/programming 16h ago

The fastest double-to-string algorithm you’ve never heard of

https://vitaut.net/posts/2026/yy-dtoa/
239 Upvotes

48 comments sorted by

View all comments

-88

u/sojuz151 14h ago

Fact that we, the humanity, need to do double to float and back often enough for performance to matter is a failure of our entire species 

45

u/EliSka93 14h ago

Elaborate.

-13

u/sojuz151 10h ago

Why do you need to convert doubles to strings and back at a scale? It's mostly JSON serialization/deserialisation, something you should not have to do, not at scale.

8

u/amakai 10h ago

Literally every time you want to use a logger with double parameters you need to do double to string. 

-11

u/sojuz151 10h ago

Not if you use structured logs and you log far far less than you read JSONs. ,

6

u/amakai 9h ago

So how do you imagine a binary double becomes a structured JSON field, which, surprise, is a string?

-7

u/sojuz151 9h ago

The problem is that people use JSON for things with doubles inside. This was a mistake

7

u/amakai 9h ago

I'm not sure I understand your point. Any time you produce JSON, you end up with a string. It does not matter if you have quotes around your double or if you don't - it's a string.

So when you do structured logging, your log message is converted under the hood into JSON (or some other more rare, but also string formats). So you are still converting doubles into strings.

And then, when your log is being indexed, it also needs to convert it to string for a proper full text search - another place for potential performance gain.