News for hackers. Stuff that matters.
Re:“Clean” Code, Horrible Performance by badsectoracula on Tuesday February 28, 2023 @06:14PM (#34976298)
If your profiler doesn't show any hotspots (which is incredibly rare in practice) and your program is still slow, it means you can simply pick any of whatever functions/methods show up near the top to optimize.

If your program isn't slow then you don't need to bother making it any faster. Even Michael Abrash, who specializes in code optimization, once explicitly wrote in his graphics programming black book that "The objective (not always attained) in creating high-performance software is to make the software able to carry out its appointed tasks so rapidly that it responds instantaneously, as far as the user is concerned. In other words, high-performance code should ideally run so fast that any further improvement in the code would be pointless [..] Notice that the above definition most emphatically does not say anything about making the software as fast as possible".[0]

[0] https://www.jagregory.com/abrash-black-book/#understanding-h...

Re:“Clean” Code, Horrible Performance by saagarjha on Tuesday February 28, 2023 @06:17PM (#34976333)
> If your profiler doesn't show any hotspots (which is incredibly rare in practice) and your program is still slow, it means you can simply pick any of whatever functions/methods show up near the top to optimize.

No, though s/any/many/ would make this true.

Re:“Clean” Code, Horrible Performance by jbverschoor on Tuesday February 28, 2023 @06:59PM (#34976730)
Sure.. but the overall performance is in the cpu/vm, kernel, OS, UI, vm, electron, node, browser, javascript vm. etc etc

There are no hotspots. Computing has become lukewarm by default, and just like the globe, it's slowly heating up.

Re:“Clean” Code, Horrible Performance by fvdessen on Tuesday February 28, 2023 @09:55PM (#34978201)
Think of using slow patterns as using a slow programming language. After you've optimised your python program and eliminated all hotspots, the python profiler isn't going to say 'hey, this could be still 10x faster if rewritten in go'. Note that if you write a graphics engine, you aren't going to use python or even go, but something more like c, c++, rust, even though your code would be cleaner in python. Clean code techniques elevate your level of abstraction and prevent some problems, but at the (significant) cost of performance. It's of course always a matter of trade-offs and this matters more or less depending on which problem you are trying to solve.
Re:“Clean” Code, Horrible Performance by DeathArrow on Wednesday March 01, 2023 @03:48AM (#34980173)
>Clean code techniques elevate your level of abstraction and prevent some problems

What problems do they prevent?

Re:“Clean” Code, Horrible Performance by Applejinx on Wednesday March 01, 2023 @06:47AM (#34981292)
Unemployment :)

If you're able to make a program into a sort of puzzle concealing its state inside a twisty maze of tiny virtual functions so it's impossible to see plainly how anything is done, then you become indispensable as the only one who's internalized how the thing works.

And then you insist it's all for easier comprehension… for those sufficiently intelligent to comprehend it.

Re:“Clean” Code, Horrible Performance by trashtester on Wednesday March 01, 2023 @08:30AM (#34982138)
Even more new clothes for the emperor.
Re:“Clean” Code, Horrible Performance by fvdessen on Wednesday March 01, 2023 @09:03AM (#34982488)
If the average programmer didn’t use ‘clean code’ techniques they would end up with crazy spaghetti, not the fast and clear code shown in the video. (the average programmer is not on HN and can’t do fizzbuzz)
Re:“Clean” Code, Horrible Performance by badsectoracula on Wednesday March 01, 2023 @10:19AM (#34983296)
> After you've optimised your python program and eliminated all hotspots, the python profiler isn't going to say 'hey, this could be still 10x faster if rewritten in go'.

No it wont say something like that but if you profile Python itself and see that a lot of time is spent in Python you can get a hint that rewriting it in another language that doesn't have Python's overhead might help.

Re:“Clean” Code, Horrible Performance by boredhedgehog on Wednesday March 01, 2023 @02:47AM (#34979797)
> If your program isn't slow then you don't need to bother making it any faster.

But you can only judge that for the very limited set of hardware you personally have access to. You might have many users -- or potential users -- with slower CPUs.

Re:“Clean” Code, Horrible Performance by badsectoracula on Wednesday March 01, 2023 @10:15AM (#34983262)
This is where having a target hardware comes in. Aside from doing it for fun, there isn't much of a point to care for 15 year old PCs for example.
Re:“Clean” Code, Horrible Performance by DeathArrow on Wednesday March 01, 2023 @03:46AM (#34980160)
Casey does not advocate for code optimization. Not writing code in a way that is known to degrade performance does not mean you are doing optimization.
Re:“Clean” Code, Horrible Performance by amelius on Wednesday March 01, 2023 @04:58AM (#34980582)
No, if one day you decide to run it on a less capable CPU, it's nice if the optimization work has been done.
Re:“Clean” Code, Horrible Performance by badsectoracula on Wednesday March 01, 2023 @10:17AM (#34983282)
This is the same as trying to guess the future that creates "astronautical architecture". You set a target hardware you're willing to support (e.g. PCs released in the last 10-15 years) and anything less is out of scope of the project. You don't need to support 8086 PCs for example.

(ignoring projects made for fun of course)