5 ms·
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 f
by badsectoracula 4y ago
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-high-performance https://www.jagregory.com/abrash-black-book/#understanding-h...
- saagarjha 4y ago> 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.
- jbverschoor 4y agoSure.. 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.
- fvdessen 4y agoThink 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.
- DeathArrow 4y ago>Clean code techniques elevate your level of abstraction and prevent some problems What problems do they prevent?
- Applejinx 4y agoUnemployment :) 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.
- trashtester 4y agoEven more new clothes for the emperor.
- fvdessen 4y agoIf 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)
- badsectoracula 4y ago> 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.
- boredhedgehog 4y ago> 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.
- badsectoracula 4y agoThis 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.
- DeathArrow 4y agoCasey 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.
- amelius 4y agoNo, if one day you decide to run it on a less capable CPU, it's nice if the optimization work has been done.
- badsectoracula 4y agoThis 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)