7 ms·
The Uselessness of "Fast" and "Slow" in Programming
- IshKebab 1y ago> The question I’m talking about here is, is “slow”, as a word standing by itself with no further characterization, even an applicable concept? Yes, because there's usually context. To use his cgo example, cgo is slow compared to C->C and Go->Go function calls.
- kragen 1y agoBut what matters here is probably whether it's slow compared to the code being invoked via cgo, which is only true for pretty fine-grained APIs.
- Lio 1y agoI mean, probably what really matters is how slow things are compared to the network latency of a HTTP request. In web-development arguing about Go-Go vs CGo-Go times is probably inconsequential.
- kragen 1y agoLatency and throughput are not interchangeable, and it is entirely normal to do millions of subroutine calls per HTTP request, so even if latency is your only concern, a subroutine call operation with a latency ten thousand dollars faster than the HTTP request might still be too slow. Latency is not interchangeable with throughput because, if your single 8-core server needs to serve 200 HTTP requests per second, you need to spend less than 40 core-milliseconds per request on average, no matter whether the HTTP clients are 1ms away or 1000ms away.
- chrisweekly 1y ago"ten thousand dollars faster"?
- kragen 1y agoYes, at the abstraction level of money, many more things become interchangeable, but in order to have something worth spending money on, we have to distinguish between those things.
- IshKebab 1y agoWhether it matters depends on what you're using it for. The point is that saying "cgo is slow" is meaningful.
- kragen 1y agoIt can be meaningful, depending on how much context there is, but statements like that often suffer a kind of context collapse where they are transplanted from contexts where they are clearly true to contexts where they are debatable or even false. Jerf gives a very clear example of this in https://news.ycombinator.com/item?id=45966261 https://news.ycombinator.com/item?id=45966261.
- ncruces 1y agoMore important, IMO, are the non-local effects of using CGO (vs. eg. Go asm), and which are harder to understand.
- jerf 1y agoThe problem with that context is that it is neither good, nor useful. For good, an example that perhaps I should lift into the essay itself is probably more useful than an explanation. A year or two or so back, there was some article about the details of CGo or something like that. In the comments there was someone who was being quite a jerk about how much faster and better Python's C integration was. This person made several comments and was doing the whole "reply to literally everyone who disagrees", insulting the Go designers, etc. until finally someone put together the obvious microbenchmark and lo, Go was something like 25% faster than Python. Not blazingly faster, but being faster at all rather wrecked the thesis. Nor would it particularly matter that "this was a microbenchmark and those don't prove anything" as clearly the belief was that CGo was something like an order of magnitude slower if not more so even a single microbenchmark where Go won was enough to prove the point. While the being a jerk bit was uncalled for, I don't blame the poster for the original belief though. Go programmers refer to CGo as "slow". Python programmers refer to their C integration as "fast". It is a plainly obvious conclusion from such characterizations that the Python integration is faster than Go. Only someone being far, far more careful with their uses of "fast" and "slow" than I am used to seeing in programming discussions would pick up on the mismatch in contexts there. As such, I don't think that's a particularly good context. People who use it do not seem to have a generally unified scale of "fast" and "slow" that is even internally consistent, but rather a mismash of relatively inconsistent time scales (and that's not "relatively inconsistent" as in "sort of inconsistent" but "inconsistent relative to each other" [1]), thus making "fast" and "slow" observably useless to compare between any of them. For useful, I would submit to you that unless you are one of the rare exceptions that we read about with those occasional posts where someone digs down to the very guts of Windows to issue Microsoft a super precise bug report about how it is handling semaphores or something, no user has ever come up to you and said that your software is fast or slow because it uses CGo, or any equivalent statement in any other language. That's not an acceptance criterion of any program at a user level. It doesn't matter if "CGo is slow" if your program uses it twice. The default context you are alluding to is a very low level engineering consideration at most but not something that is on its own fast or slow. A good definition of fast or slow comes from somewhere else, and maybe after a series of other engineering decisions may work its way down to the speed of CGo in that specific context. 99%+ of the time, the performance of the code will not get worked down to that level. We are blinded by the exceptions when it happens but the vast majority of the time it does not. By this, I mean it is an engineering mistake, albeit a very common one, to obsess in this "default context" about whether this technology or that technology is fast or slow. Programmers do this all the time. It is a serious, potentially project-crashing error. You need to start in the contexts that matter and work your way down as needed, only rarely reaching this level of detail at all. As such, this "default context" should be discarded out of your mind; it really only causes you trouble and failure as you ignore the contexts that really matter. [1]: Of the various changes to English as she is spoken over the last couple of centuries, one of my least favorite is how a wide variety of useful words that used to have distinct meanings are now just intensifiers.
- shevy-java 1y ago> A software engineer may be slicing and dicing nanoseconds People typically live only once, so I want to make the best use out of my time. Thus I would prefer to write (prototype) in ruby or python, before considering moving to a faster language (but often it is not worth it; at home, if a java executable takes 0.2 seconds to delete 1000 files and the ruby script takes 2.3 seconds, I really don't care, even more so as I may be multitasking and having tons of tabs open in KDE konsole anyway, but for a company doing business, speed may matter much more). It is a great skill to be able to maximize for speed. Ideally I'd love to have that in the same language. I haven't found one that really manages to bridge the "scripting" world with the compiled world. Every time someone tries it, the language is just awful in its design. I am beginning to think it is just not possible.
- dominicrose 1y agoIn my experience, Ruby starts fast and does everything fast. But you can make a case against Ruby if you want, by making it do a lot of CPU work for a long time. Java may take some time to warm up and then it will destroy Ruby. But why not simply write the code that needs to be fast in C and then use call it from Ruby?
- skydhash 1y agoIn the unix world, the usual philosphy is tko start with a script (bash, awk, perl,…), then move to C and the like when the usecase is understood enough. So it’s more like a switch from programs and ipc to libraries and function calls. But there are stuff, you immediately know you want a program, but they’re likely to be related to stuff like pure algorithms, protocols and binary file formats
- pdimitar 1y ago> But why not simply write the code that needs to be fast in C and then use call it from Ruby? Because often that's a can of worms and because people are not as good with C as they think they are, as evidenced by plenty of CVEs and the famous example of quadratic performance degradation in parsing a JSON file when the GTA V game starts -- something that a fan had to decompile and fix themselves. For scripting these days I tend to author small Golang programs if bash gets unwieldy (which it quickly does; get to 100+ lines of script and you start hitting plenty of annoyances). Seems to work really well, plus Golang has community libraries that emulate various UNIX tools and I found them quite adequate. But back to the previous comments, IMO both bash and Ruby are quite fine for basic scripting... if you don't care about startup time. I do care in some of my workflows, hence I made scripts that pipe various Golang / Rust programs to empower my flow. But again, for many tasks this is not needed.
- stevage 1y agoMore useful words are "negligible" and "problematic".
- w10-1 1y ago> More useful words are "negligible" and "problematic". Yes, thank you! Worth emulating. By comparison: > A characteristic of these systems spanning so many orders of magnitude is that it is very frequently the case that one of the things your system will be doing is in fact head-and-shoulders completely above everything else your system should be doing, and if you have a good sense of your rough orders of magnitudes from experience, it should be generally obvious to you where you need to focus at least a bit of thought about optimization, and where you can neglect it until it becomes an actual problem.
- My_Name 1y agoOften, a user presented with a progress bar will wait much longer without frustration than a user without one will do. Sometimes, making the code faster is non-trivial and is not cost-effective when compared to making the user simply not complain.
- marginalia_nu 1y agoLatency is weird in UX. Being too fast can also be jarring. If you hit a button that's supposed to do something (e.g. "send email" or "commit changes") and the page loads too fast, say in 20ms, a lot of users panic because they think something is broken.
- CyberDildonics 1y agoThe solution is user feedback, not rationalizing making software slow to use a scripting language or electron or whatever other shortcut that is bad for a user.
- NebulaStorm456 1y agoSimilar to the fact that humans need enlarged, human scale-size input and output mechanisms (keyboard, mouse, smartphones, control panel buttons in cockpit). The actual meat of the computation can be packaged in a nicely small form factor.
- actionfromafar 1y agoVery true. And it sort of indicates that it is broken or at least unusual. If sending an email at least means "my email server has it now", then 20ms for that to happen would be a very unusual setup. So if the dialog closes in 20ms if likely means the message was queued internally by the email client and then I would be worried that the queue will not be processed for whatever reason.
- marginalia_nu 1y agoYeah it's usually a problem with asynchronous UIs. You basically need to simulate a synchronous UI to make the interface seem reliable. The file copy dialog in modern windows versions also has (had) this weird disconnect between the progress it's reporting and what it's actually doing. Seems very clear one thread is copying and one is updating the UI, and the communication between the two seems oddly delayed and inaccurate. The progress reporting is very bizarre and sometimes the copying doesn't seem to start immediately. It feels markedly flakey.
- dlisboa 1y ago> Most people, most of the time, doing most web work, are so thoroughly outclassed on speed by their web framework and server that the speed of their choice is irrelevant. Which means they should be selecting based on all the other relevant features. I disagree with that as the choice of framework doesn't impact just the request/response lifecycle but is crucial to the overall efficiency of the system because they lead the user down a more or less performant path. Frameworks are not just HTTP servers. Choosing a web framework also marries you to a language, hence the upper ceiling of your application will be tied to how performant that language is. Taking the article's example, as your application grows and more and more code is in the hot path you can very easily get into a space where your requests that took 50ms now take 500ms.
- giancarlostoro 1y agoYou can also squeeze performance out of most languages by knowing the bottlenecks and working around them. Even Go you can squeeze performance out of if you really need to and want to.
- immibis 1y agoGo is far from the slowest language even though it has GC.
- actionfromafar 1y agoIf we allow for warmup, Java is pretty fast for many workloads. https://madnight.github.io/benchmarksgame/go.html https://madnight.github.io/benchmarksgame/go.html
- ecshafer 1y agoJava is very fast. You just have to account for the amount of absolutely terrible written Java code full of 6 levels of inheritance, 6 levels of nested loops and AbstractFactoryFactoryFactoryProviderImpls out there to slow it down. I swear I have seen so much Java code that in the name of "abstraction" and "maintainability" they would take x + y and turn it into 8 classes and method calls.
- fabian2k 1y agoI think people tend to overestimate how much certain choices matter for performance. But I don't agree that the speed of frameworks doesn't matter in most cases. To me the base performance of such a framework is essentially like a leaky abstraction. The moment I hit any bottleneck I suddenly need to understand how the framework works internally to work around it. I'm unlikely to get bottlenecked on well written and idiomatic code in a slower framework. But I'm much more likely to accidentally do something very inefficient in such a framework and then hit a bottleneck. I also think the difference in ergonomics and abstraction are not that huge between "slow" and "fast" frameworks. I don't think ASP.NET Core for example is significantly less productive than the web frameworks in dynamic languages if you know it.
- marginalia_nu 1y agoI think the problem with optimization as an approach to getting a program to be fast is that it's fairly often not bottlenecks that are the problem, but architectural choices that don't show up in the profiler's flame charts. Even if you find a slow function that constitutes 20% of the runtime, and optimize the living hell out of it to cut out 20% of the execution time, guess what your program is now about 4.1% faster.
- QuadmasterXLII 1y agoOn the subject of human comprehension of ten orders of magnitude: Pretty often you have a hot path that looks like a matmul routine that does X FMAs, a physics step that takes Y matmuls, a simulation that takes Z physics steps, an optimizer that does K simulations. As a result, estimating performance across 10 orders of magnitude is just adding the logs of 4 numbers, which pretty well works out as “Count up the digits in XYZK, don’t get to 10” which is perfectly manageable to intuit
- 1970-01-01 1y ago>number of orders of magnitude, but are doing engineering across the entire range. This in a way highlights the knowledge gap that exists in American manufacturing. Physical parts are designed to work in terms of cycles, which can span both decades and milliseconds. Engines in particular need to work in terms of milliseconds and decades, but there are other vehicle parts such as airbags, pumps, and steering and suspension components that need to be designed for massive orders of magnitude.
- deleted 1y ago[deleted]
- voidmain 1y agoIf you are building an application, you can and should know what your absolute time/power/cost budget is and evaluate the "speed" of operations against this absolute standard. It does not matter that some operation is 100x slower than it could be if it is still 10,000x faster than you need it to be. But a lot of software engineering goes into building tools, libraries, frameworks, and systems, and even "application" code may be put to uses very distant from the originally envisioned one. And in these contexts, performance relative to the "speed of light" - the highest possible performance for a single operation - can be a very useful concept. Something "slow" that is 100x off the speed of light may be more than fast enough in some circumstances but a huge problem in others. Something "very fast" that is 1.01x the speed of light is very unlikely to be a big problem in any application. And this is true whether the speed of light for the operation in question is 1ns or 1min.
- deleted 1y ago[deleted]
- taeric 1y agoI mean, sure. But it is totally worth knowing what you have to wait for, versus what you can do right away. I honestly don't know if async makes this easier or harder. It makes it easier to write sections of code that may have to wait for several things. It seems to make it less likely to write code that will kick off several things that can then be acted on independently when they arrive.
- Too 1y agoObligatory link to Latency numbers every programmer should know. https://colin-scott.github.io/personal_website/research/interactive_latency.html https://colin-scott.github.io/personal_website/research/inte...
- squillion 1y agoI lost him when he rounded the orders of magnitude.