Comment by mkeeter
4 years ago
Blog author here! Thanks to HN for warning me about sscanf at exactly the right time – within a day of me trying to load some ASCII STLs and noticing it was slow...
Linked deep in the Twitter replies [1], there's an open glibc issue about this, dating back to 2014:
https://sourceware.org/bugzilla/show_bug.cgi?id=17577
C doesn't have any requirements on the complexity of sscanf, so it might not be a bug per se, but it's certainly... a pitfall.
[1] https://twitter.com/impraxical/status/1367194430835425283
I love the format of this blog post. Perfect length. Perfect detail. You don't waste words. A good number of images.
I like this blog post but I also happen to quite like long forms like these, too: https://mango.pdf.zone/finding-former-australian-prime-minis... / https://apenwarr.ca/log/20201227
The mango blog post was incredibly entertaining. Thanks for sharing.
And it works without javascript!
all blogs work without javascript.
Hey, Matt, neat to see you here and congrats on making the front page! Recognize you from the Formlabs forums & conferences.
Love that notion of professional empathy underscoring your message in the blog post.
Hey RK! Thanks for the kind words – hopefully I'll see you again, once we're back to holding in-person events!
I know Matt too, primarily from him rejecting my Libfive PRs for being "too 1337".
But seriously, Matt, I might have a project for an in-person event regarding printing robots. Stay tuned--to what channel I don't know.
IMO the lack of a complexity requirement is a bug in the C standard. And really it’s a bug in the implementation(s?) too. If it can be done on O(1), shame on library authors for doing it in O(n). If you want programmers to trust library authors, don’t do this to us. Maybe std::from_chars FTW?
This is not a complexity issue with the function. The function is linear to the input, as it should be. The problem is that the implementation does more work then it needs to (it doesn't need the length of the string). It should be linear to the end of parsing not the end of string. The complexity in this case comes from the loops calling it.
Shouldn’t we just come clean and admit to ourselves that there is no such thing as the C standard? There is a collection of loosely related languages that look similar and that collectively we call C, but really they’re all completely different and share almost no interoperability or common characteristics. And those standards that do exist provide almost no ability to reason about your code including things like ordering of statements.
No, that's complete nonsense.
Here's the latest revision of the standard: https://www.iso.org/standard/74528.html
C has had a well-defined memory model since C11, I believe (re: "ordering of statements").
20 replies →
Thank you for introducing me to the concept/term Ascetic programming. Not sure how widely used it is, but I find it more fitting for what I try to do than minimalistic or KISS.
Also, it is great to see someone write
I always find pleasure seeing projects which highlight just how fast modern computers really are.
Re-read my comment and to be clear, the quote and the last paragraph are not related. The last sentence was meant to refer to the Erizo project as a nice single purpose high performing tool, not as a comment to the bug that made it slow.
When looking at loading performance of STLs, you may want to look at this: https://papas-best.com/stlviewer_en
printf and scanf match nicely with their format specifiers, so the serialization and deserialization can be maintained nicely in lockstep.
to avoid the quadratic overheating sttlen you can simply use fmemopen(3), which makes the temporary sscanf FILE object explicit and persistent for the whole parse, and needs just one strlen call.
https://news.ycombinator.com/item?id=26343149
Thanks for the great blog post, and congrats on finding that long dormant bug!
Love the post, except for the title. It is too click-baity.