r/cpp • {fmt} • Jul 20 '26

Żmij 1.1 released with fixed notation support, up to 38% faster double-to-string conversion, SIMD-optimized float formatting, a smaller binary footprint and more

41 Upvotes

40 comments sorted by

View all comments

Show parent comment

6

u/jk-jeon Jul 20 '26

I think it's basically because our world isn't ideal. It just happens that people abuse text format a lot when binary clearly would have been preferable. It seems in many fields text formats are just standard for no reason or for questionable reasons or for reasons that made sense 3-4 decades ago but not so much these days. But if it's already an industry standard, then it's game over. Just follow the practice or you'll be hated by everyone else.

One such example: https://en.wikipedia.org/wiki/Wavefront_.obj_file

I mean, I don't get why it should be a text format. Is it even possible to edit a 3D model using a text editor when the model has 1000+ vertices and complicated geometry? But for whatever reason this seems to be a widely adapted industry standard. And apparently printing numbers was indeed a serious bottleneck:

https://aras-p.info/blog/2022/02/03/Speeding-up-Blender-.obj-export/

According to the post it turned out that the biggest cause was the locale nonsense which effectively killed parallelization, but the contribution from replacing the number conversion routine by a faster one was non-negligible too.

4

u/Dragdu Jul 20 '26

Text formats are dead simple to hack on and debug, which can be very strong advantage in hobbyist space. Being line oriented also allows you to do things like diff files, git files and so on.

Another example is DIMACS. Would it be more efficient to have it be binary format? Hell yes. Would it reach the same level of adoption, becoming de-facto standard? I am willing to bet very good money on "no".

4

u/ack_error Jul 21 '26

The advantage of a text format like .obj is that it's stupidly simple. I can write an .obj file from almost anywhere using simple text I/O commands, and the result can be diffed/merged, searched with grep, and viewed/edited in any standard text editor.

Would I base an entire full-size game on .obj? No. But I'd rather use a text-based model format like USD than an undocumented binary format like FBX that is practically unusable without linking in a huge library. And while you wouldn't ordinarily want to edit them directly as text, it's easier to figure out what blew up the loader when you can look at the text file and find that some tool wrote NaN where there was supposed to be a vertex coordinate.

If there were good, standard, generic binary formats then this wouldn't be an issue, but there aren't. The main ubiquitous structured data formats are all text -- simple line oriented, XML, JSON, etc. There have been many attempts at general binary formats, but they either don't get enough traction or make people shiver in terror when mentioned (ASN.1). Bespoke binary formats for specific purposes tend to have poor tooling support or just plain bad design, even simple things like not having an identifiable format header.

2

u/jk-jeon Jul 21 '26

It seems this sort of resonates with what I mean by "world is not ideal":

Bespoke binary formats for specific purposes tend to have poor tooling support or just plain bad design, even simple things like not having an identifiable format header.

What I guess is that binary formats tend to have harder time getting over the "chicken-and-egg phase of adaption" when they are born.