17 ms·
If somebody finds a 20% improvement in stdio, every program in the world using stdio benefits from that improvement.
by adrianN 6y ago
If somebody finds a 20% improvement in stdio, every program in the world using stdio benefits from that improvement.
- geocar 6y agoYou're right in principle, but I think you're overestimating both the cost of discovery and the value of a 20% improvement: A 20% improvement on a microbenchmark (say float to string conversion) when only 0.01% of your application run-time was spent converting floats to strings nets you fuck all. It might also take weeks-to-months to identify some improvement and get it integrated into each libc implementation. It's so much easier, and the gains are so much bigger to just change the application, and given people's dependency on stdio is usually quite low, that's what most people do.
- chrchang523 6y agoMy experience is primarily in scientific software which has more string<->number conversions than the norm, so others' mileage may vary, but I can confirm that a lot of widely used C and C++ programs are significantly slowed down by their use of standard library I/O functions. Often written by domain experts with more than a decade of experience, not noobs. Yes, once a particular programmer knows about the problem, they can solve it pretty quickly by switching to faster and narrower functions. But this is happening one programmer at a time. Practically everyone is still learning the wrong default, and switching away only after they've noticed they've been burned by it, and scientific programmers at least are being burned by enough other things that there's no guarantee that they'll ever notice this detail, even if they're generally very competent. (We're initially trained to not worry much about this sort of constant factor, after all.) The lowest-hanging fruit I see is in the compiler enhancement domain. They already e.g. inspect printf-family format strings, redirect the containing function call to fputs/memcpy when the string contains no format placeholders, and when there are format placeholders a warning is printed when the number of additional arguments does not match the number of format placeholders. If we could count on snprintf(buf, bufsize, "count: %d", k) being compiled down to little more than a 7- or 8-byte memcpy followed by a call to a dedicated integer-to-string function, I think the associated gain would be far more than "0.01%".
- geocar 6y ago> Practically everyone is still learning the wrong default I think this is a much deeper problem than stdio.
- otabdeveloper4 6y ago> A 20% improvement on a microbenchmark (say float to string conversion) when only 0.01% of your application run-time was spent converting floats to strings nets you fuck all. Your logic is incorrect. A typical REST API might make millions of float<->string conversions in one request. Making it twice as fast might mean shaving many milliseconds from your median response time, which is a huge deal.
- gnulinux 6y agoIf stdio was 100% of all programs in the world, they'd be a 20% improvement. In reality, stdio takes more like 1% of any normal program so even 20% improvement will be barely noticeable.
- adrianN 6y agoIf stdio takes 1% of all computer time and computers take 1% of the world's electricity to run, a 20% improvement in stdio time saves many tons of CO2.
- jcranmer 6y agoBut it would still be 0.001% of the way we need to go.
- gnulinux 6y agoYou're assuming most programs run start to finish then the machine shuts down. That's probably <1% of all machines. Most machines run on a loop. So when they don't do stdio either they do some other useful computation (e.g. if a game engine is not stalled on stdio, it can process a few more frames per second) or they run an idle process which consumes less energy but very far away from 0. So, no even that logic doesn't work here. Saving 20% stdio cycles will probably not even have measurable effect on global enegy consumption.
- dgritsko 6y agoAmdahl's Law does a nice job of expressing this idea: https://en.wikipedia.org/wiki/Amdahl%27s_law https://en.wikipedia.org/wiki/Amdahl%27s_law