News for hackers. Stuff that matters.
Re:“Clean” Code, Horrible Performance by simplotek on Tuesday February 28, 2023 @04:52PM (#34975385)
> That's really not even close to true. Loading random websites frequently costs multiple seconds worth of (...)

You attempted to present an argument that's a textbook example of an hyperbolic fallacy.

There are worlds of difference between "this code does not sit in a hot path" and "let's spend multiple seconds of local processing time".

This blend of specious reasoning is the reason why the first rule of software optimization is "don't". Proponents of mindlessly going about the 1% edge cases fail to understand that the whole world is comprised of the 99% of cases where shaving off that millisecond buys you absolutely nothing, with a tradeoff of producing unmaintainable code.

The truth of the matter is that in 99% of the cases there is absolutely no good reason to run after these relatively large performance improvements if in the end the user notices absolutely nothing. Moreso if you're writing async code that stays far away from any sort of hot path.

Re:“Clean” Code, Horrible Performance by heisenbit on Tuesday February 28, 2023 @05:08PM (#34975608)
How does an organization which has been built on 99% not doing optimization recognize the one percent where it matters a lot?
Re:“Clean” Code, Horrible Performance by eropple on Tuesday February 28, 2023 @05:13PM (#34975661)
In my experience: a profiler, usually. Just because I can throw down a lot of code quickly doesn't mean I don't have the tools to analyze code when I go "hmm, that seems slow".
Re:“Clean” Code, Horrible Performance by incrudible on Wednesday March 01, 2023 @04:27AM (#34980375)
That works for big hotspots, but not for the tiny papercuts that make every little thing 10x slower.
Re:“Clean” Code, Horrible Performance by eropple on Thursday March 02, 2023 @10:33AM (#34996909)
Sure. That's a tradeoff you consciously make to get the thing out the door. That's what technical debt is. You pay it down later. (Or you go bankrupt and it doesn't matter anymore.)
Re:“Clean” Code, Horrible Performance by incrudible on Friday March 03, 2023 @03:40PM (#35014704)
The blog post challenges the assumption that the slower version is any way improving productivity. At least for the given example, I agree.
Re:“Clean” Code, Horrible Performance by Turskarama on Tuesday February 28, 2023 @06:05PM (#34976197)
Testing, do you not do testing? Use the software. If it seems slow drill down and find the critical path and optimize it.
Re:“Clean” Code, Horrible Performance by yuliyp on Tuesday February 28, 2023 @06:44PM (#34976589)
Testing is often not enough. Developers might have a few test cases with a few records, or a few other users. Real users might do more with it, and things which perform fine in testing suddenly turn into real performance bottlenecks when you're loading an order list with a thousand entries in it instead of two.
Re:“Clean” Code, Horrible Performance by Turskarama on Tuesday February 28, 2023 @10:01PM (#34978248)
When I said testing that includes integration testing, not just unit tests. We do this exact thing with queries that are known to be complex, run them against databases the same size and complexity as real production databases. It's not hard.
Re:“Clean” Code, Horrible Performance by rerdavies on Tuesday February 28, 2023 @10:40PM (#34978496)
Building representative databases is not straightforward.

If you're lucky enough to eat your own dogfood, run unit tests against a copy(!) of your in-house database. A utility to anonymize the data was a fairly significant investment, but absolutely worth it in the long run. Being able to run and monitor benchmark unit tests for selected critical operations on enterprise-scale test data as part of the continuous-build process: fabulous!

Re:“Clean” Code, Horrible Performance by julik on Tuesday February 28, 2023 @06:23PM (#34976391)
By someone presenting plausible evidence that not having that 1% optimised costs the organization money/business, and leadership that would listen
Re:“Clean” Code, Horrible Performance by saagarjha on Tuesday February 28, 2023 @06:26PM (#34976421)
In any organization it generally pays off to have most people have a basic knowledge of a subject and then hire domain experts to drive most of the impact. For security, for example, this typically manifests as having very general "best practices" for most developers to follow and then a small team that handles anything that requires advanced understanding of the area.

How this typically works with performance is very similar, with a small team working to identify problematic areas where optimization would drive the highest impact, and the rest of the organization keeping performance in mind but not otherwise concerned with it in their day-to-day work.

Re:“Clean” Code, Horrible Performance by simplotek on Tuesday February 28, 2023 @07:28PM (#34977046)
> How does an organization which has been built on 99% not doing optimization recognize the one percent where it matters a lot?

If you can't recognize the percent where it matters a lot, clearly that percent does not exist and you're bothering about nothing.

I see a lot of talk about the importance of tuning Formula 1 cars in a world where everyone drives ford fiestas.

Re:“Clean” Code, Horrible Performance by rerdavies on Tuesday February 28, 2023 @10:24PM (#34978383)
Profiling. If you're not profiling, you're completely wasting your time. The 1% is almost never where you think it is.

And when you do identify the 1%, you need to be testing optimizations with a profiler constantly while optimizing. Profile. Do some optimization. Profile again. Roll back if not successful. Repeat until done. It's impossible to optimize well if you're not doing profiling.

The ultimate tools would be either Intel's profiling tools, or ARM's profiling suite (both very expensive). But MSVC and GCC do a fantastic job of scheduling instructions to avoid pipeline stalls these days, so these deep profiling tools are unlikely to gain more than 2 or 3% performance increases these days. (Worthwhile pretty much only if you're writing GPU drivers for NVidia or AMD).

Taken as a given that 100% of your code is at least algorithmically correct in the first place. (Appropriately better than O(N^2) whenever possible).

- Former writer of graphics drivers, currently audio DSP engineer.

Re:“Clean” Code, Horrible Performance by anonymoushn on Tuesday February 28, 2023 @11:18PM (#34978701)
A hash table that accesses a minimum of 2 cache lines per query can be algorithmically correct and also admit a 100% speedup.
Re:“Clean” Code, Horrible Performance by themulticaster on Wednesday March 01, 2023 @02:29PM (#34987080)
I'm not familiar with how it compares to ARM/Intel's profiling tools, but I found the Linux perf suite to be very capable (though limited to Linux obviously). And Hotspot [1] allows effortless profile visualization using flame graphs, including some very interesting features such as off-CPU time profiling [2]. "perf record" coupled with Hotspot forms a very smooth edit-compile-profile cycle.

[1] https://github.com/KDAB/hotspot

[2] https://github.com/KDAB/hotspot#off-cpu-profiling

Re:“Clean” Code, Horrible Performance by rerdavies on Thursday March 02, 2023 @02:00AM (#34992913)
Agreed. Linux perf tools are perfectly acceptable for all but the most ultra-extreme optimization tasks.

VTune allows you to determine where pipeline stalls are occurring at the instruction level (for that last 2 or 3% gain in performance). I haven't worked with ARM profilers (way out of my price range), but I assume, given the exorbitant price, they provide the same sort of in-depth analysis. Probably a handful of people on the planet that need that kind of in-depth analysis.

Re:“Clean” Code, Horrible Performance by loup-vaillant on Tuesday February 28, 2023 @05:53PM (#34976080)
I realised when I implemented EdDSA for Monocypher that optimisations compound. When I got rid of a bottleneck, I noticed that another part of the code was the new bottleneck, and some of the optimisations compounded multiplicatively. It took many changes before I finally started to hit diminishing returns and stop. All while restricting myself to standard C99, and trying fairly hard not to spend too many lines of code on this.

My point being, if most of the program is slowed down by a slew of wasted CPU cycles (costly abstractions, slow interpreted language…), there's a good chance what should have been obvious bottlenecks get drowned in a see of underperformance. They're harder to spot, and fixing them doesn't change much.

So before you even get to actual optimisation, your program should be fast enough that actual optimisations have a real impact. And yes, actual optimisation should be done quite rarely. But first, we need to make sure our programs aren't as slow as molasses. See https://www.youtube.com/watch?v=pgoetgxecw8

Re:“Clean” Code, Horrible Performance by simplotek on Tuesday February 28, 2023 @07:25PM (#34977014)
> I realised when I implemented EdDSA for Monocypher that optimisations compound.

I feel you're missing the whole point.

It's immaterial whether anyone can get to optimizations that compound multiplicatively. The whole point is that halving something that costs nothing earns you nothing. That's the whole point. Go ahead and shave off that millisecond. Will anyone actually notice whether you add or remove that penalty? Odds are, not at all.

Re:“Clean” Code, Horrible Performance by loup-vaillant on Tuesday February 28, 2023 @07:59PM (#34977314)
People did notice. Quite a few happy users are glad signature verification took less than a second instead of more than 3. Or 30, if you compare to some of the alternatives. Others love the fact it uses 2KB of stack space instead of 5.

Monocypher's speed was actually an important component in its success in the embedded market, even though I didn't explicitly target it initially (I was lucky my portability driven decisions made it a good fit there).

Re:“Clean” Code, Horrible Performance by tharkun__ on Tuesday February 28, 2023 @09:05PM (#34977836)
Not your parent but I think that is exactly the point lots of people here are making.

There definitely are niches where there are quite a few performance optimization opportunities that users do care about.

In your example making something a user is actively waiting for go from 3 seconds to less than one is a great optimization target. What is not a great optimization target is making something the user is actively waiting for and that takes 30ms take 25ms instead. That's wasted money on developer time.

If your "user" is a developer of embedded software with memory constraints and using your library leaves them more room that's awesome. If your user was someone using the library on a general purpose computing device with loads of memory then the 2 vs. 5 does nothing.

Re:“Clean” Code, Horrible Performance by rerdavies on Tuesday February 28, 2023 @10:05PM (#34978271)
You need to do some research on how to get modern C/C++ compilers to vectorize.;-) No assembly required, and not that hard to restructure code. (But MUCH easier in C++).
Re:“Clean” Code, Horrible Performance by anonymoushn on Tuesday February 28, 2023 @11:16PM (#34978692)
So far it seems like if you have some parsing or formatting task that can be trivially vectorized, the compiler will never do that, and you absolutely must use intrinsics.
Re:“Clean” Code, Horrible Performance by loup-vaillant on Wednesday March 01, 2023 @02:58AM (#34979856)
I tried auto-vectorisation, and it worked pretty well. But the code became just as big as using intrinsics would have (that with explicitly unrolling loops and rearranging things in memory), and intrinsics generated code that was easily 35% faster.

I decided not put it off for later, and keep things simple for now.

Re:“Clean” Code, Horrible Performance by mquander on Tuesday February 28, 2023 @06:13PM (#34976280)
The subfields of programming I know the most about are game development, networking, and web development, and in all of those, it's not the case that only 1% of the code is in the "edge case" where performance matters at all.

For example, in the case of web development, if you build a medium-sized website with React (i.e. pretty normal behavior nowadays), then if you make default decisions that don't consider performance at all, your website will end up noticeably slow, because you will:

1. Write code that re-renders components all the time during loading and UI interactions,

2. Which depend on tons of third-party dependencies that perform poorly,

3. So you end up spending a ton of time in re-renders while the site loads and while someone is using it.

Dealing with this isn't literally the same performance work that Casey put in his article, because it's at a slightly higher level of abstraction, but it requires the same mindset. It requires writing most of your code (and taking on dependencies) with performance in mind, not just 1% of it. You can't avoid it without your notion of "clean code" including some amount of mechanical sympathy, rather than just being about abstract extensibility and generalization concerns.

Re:“Clean” Code, Horrible Performance by whstl on Tuesday February 28, 2023 @07:14PM (#34976890)
It's also very easy to mess up the performance due to architecture when using modern frameworks. For example: as much as SPAs are reviled, if you have a complex enough web application with heavy components, having it being an SPA might be better in terms of perceived speed than having it do a full reload on every navigation.

This is a mistake that I see far too many government and utility sites making.

Re:“Clean” Code, Horrible Performance by Aeolun on Tuesday February 28, 2023 @07:50PM (#34977249)
Except that in React writing clean code will actually make your application faster.
Re:“Clean” Code, Horrible Performance by engineeringwoke on Tuesday February 28, 2023 @08:16PM (#34977469)
Re-renders are incredibly cheap in the big picture. They are not a source of performance bottlenecks in 99% of real world applications
Re:“Clean” Code, Horrible Performance by xtian on Tuesday February 28, 2023 @09:12PM (#34977892)
So why do 99% of real world applications run like garbage? What’s the culprit?
Re:“Clean” Code, Horrible Performance by simplotek on Wednesday March 01, 2023 @02:30AM (#34979708)
> So why do 99% of real world applications run like garbage?

If you're really interested in the impact of performance issues on everyday life, you need to provide concrete examples instead of putting up unverifiable strawmen.

The truth of the matter is that 99% of real world applications run just fine, and it doesn't pay off to invest in shaving milliseconds here or there. Would it be desirable to have a magic wand to improve some edge cases? Yeah, why not? Is it worth to pay people to spend time with a stopwatch at hand to shave off these milliseconds? Not really. It's all about tradeoffs, and there is no real world payoff in wasting developers' time to shave off that millisecond here or there.

Re:“Clean” Code, Horrible Performance by wruza on Wednesday March 01, 2023 @03:30AM (#34980042)
The promise of frameworks like React is that you write code in their way and they take care of performance, because functional, declarative and all that. You just use primitives and don’t control how it all works under the hood. Coping may be a good strategy here, but isn’t a good argument.
Re:“Clean” Code, Horrible Performance by nottorp on Wednesday March 01, 2023 @03:31AM (#34980047)
You basically waste millions of seconds of users' lifetime instead :)

Not to mention that web apps redrawing everything whenever they feel like it can almost give motion sickness, lead to clicks on the wrong things etc.

Yeah, but users' time is worthless.

Re:“Clean” Code, Horrible Performance by mtrower on Wednesday March 01, 2023 @04:00AM (#34980251)
You know, I started on some concrete examples for you, but I had to stop and back up. Really? You can't think of any examples yourself? The modern web is absolute hell to use if you aren't on modern hardware. Try it sometime; use a 10 year old phone, or an old computer that wasn't built top-of-the-line.

There's so much hardware out there that can run native applications just fine, that can play back HD video, that can run complex 3D real time video games, but crawl like molasses when loading your average webpage. Facebook and YouTube are terrible offenders, but so are your average blogs. Many banking websites are terrible (yet they don't have to be; my local credit union has a zippy website that looks attractive to boot, has modern design elements, etc.).

Maybe the hardware you're running is eye-wateringly fast, or maybe it's just barely fast enough and you don't need the cycles for anything else. But we're not talking milliseconds. We're talking order(s) of magnitude. I can't bring myself to believe you don't see at least some of it, if you just open your eyes and look around.

Re:“Clean” Code, Horrible Performance by albedoa on Wednesday March 01, 2023 @08:08AM (#34981951)
> Really? You can't think of any examples yourself?

"Unverifiable!", he wrote from within a web browser.

Re:“Clean” Code, Horrible Performance by whstl on Wednesday March 01, 2023 @04:02AM (#34980263)
Since we're talking about React, Facebook's web app is incredibly slow to me, and typing text in some fields is slower than me. As in, it sometimes takes a second for the letters to start showing. And no, it's not a browser rendering issue (even if it were it would be terrible), as disabling JS in Safari brings back the performance.

Another app that I'm not sure if it's React or not is New Reddit. It is significantly slower on my computer and on a lot of people's computer and sometimes you have to refresh the page because it consumes too much memory.

I can come up with other local examples, from Germany. Vatenfall's website seems to "traditional" page navigation, but the content is loaded via a framework. Due to having to reinitialize everything, text takes up to 5 seconds to appear when using the back button or when navigating for page to page. Similar things happen in the German Agentür fur Arbeit.

Re:“Clean” Code, Horrible Performance by cnity on Wednesday March 01, 2023 @04:22AM (#34980353)
My hot take is that React doesn't directly _cause_ slow performance, but that React is so well marketed as a first place to start for new programmers that the bar for quality is much lower than other industries (like game programming, or even "vanilla JS" which is increasingly seen as an advanced approach).
Re:“Clean” Code, Horrible Performance by sanitycheck on Wednesday March 01, 2023 @05:24AM (#34980765)
The trouble with this attitude, is that it misses the fact that the _range_ of computing power of devices which ordinary people use is probably greater now than it's ever been.

Let's not even get into low end phones in developing countries or bargain basement android tablets, let's stick with something straightforward - an ordinary PC.

I took a quick look online, sorting by cheapest first I found something with an AMD 3015e in. Based on cpubenchmark.net that gets a benchmark of 2691. Taking a look at the big list of CPUs I see that's equivalent to a powerful desktop CPU from 2008, or a decent laptop from 2012. (The Apple M2 in the current Macbook Air gets a score of 15369, just for comparison.)

So, if you're writing PC software or making a fancy web app and you want everyone to have a good experience with it then you should see how it runs on a terrible new laptop, or a 12 year old good laptop, or a 15 year old powerful desktop.

(And yeah we all have SSDs now which is much better than in the old days, and JS is generally single thread, and single threaded CPU performance has not improved so much - but I think my point still stands.)

Re:“Clean” Code, Horrible Performance by xtian on Wednesday March 01, 2023 @12:22PM (#34985111)
> The truth of the matter is that 99% of real world applications run just fine, and it doesn't pay off to invest in shaving milliseconds here or there.

You're taking deep quaffs of the Kool-Aid and so are most of the people commenting on this story. General software responsiveness and reliability (i.e., usefulness) has been in decline for decades. This is an objective fact.

Writing objective reality off as mere "milliseconds", "edge-cases", or only relevant for "toy problems" exemplifies the arrogance and severe incompetence of most programmers. People are seriously trying to talk down to Casey Muratori when in all likelihood they haven't accomplished even 1% as much as him as programmers.

I get it—no one wants to leave fantasy-land as long as the easy money is flowing. But sooner or later the glittering carriage turns back into a pumpkin.

Re:“Clean” Code, Horrible Performance by gitgud on Wednesday March 01, 2023 @01:13PM (#34986058)
Go to a slow website on Chrome. Open dev tools and turn on "enable paint flashing", you'll see a seizure inducing light show of re-rendering...

It's certainly a huge problem for real world applications

Re:“Clean” Code, Horrible Performance by mtrower on Wednesday March 01, 2023 @03:42AM (#34980124)
> the whole world is comprised of the 99% of cases where shaving off that millisecond buys you absolutely nothing

Who was talking about a single millisecond here?

I notice, broadly, two types of people who engage in these arguments.

1> OMG, computers are thousands of times faster than they were a decade ago, why is everything not lightning fast? Why are so many things slower than they were back then? Why is my chat program eating 2GB(!) of RAM?

2> Because we're busy writing six billion features on our Nth iteration of this problem space, we can't be bothered to shave a few millis bro!

And they just talk past each other.