Ask HN: How can I learn about performance optimization?
121–130 of 153 posts
Re: Ask HN: How can I learn about performance optimization?
#122Optimizing games sends you deep down a fun rabbit hole, but that will be very different than trying to optimize a Go backend server.
Re: Ask HN: How can I learn about performance optimization?
#123Full disclosure: I'm the editor in chief for the series.
Re: Ask HN: How can I learn about performance optimization?
#124One thing to keep in mind is there's three layers of optimisation: 1. The problem, 2. The algorithms, 3. Micro-optimisation. The potential gains shrink rapidly as you descend this list. A lot of people start thinking at level 3 straight away, but this is pointless if you've left performance on the table at the higher levels. For example, no amount of clever bit twiddling will compensate for the wrong algorithm, and e…
Re: Ask HN: How can I learn about performance optimization?
#125Re: Ask HN: How can I learn about performance optimization?
#126The full quote is as follows, "Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%."
He specifically does not recommend writing code that is obviously inefficient. He is clearly referring to engineers optimizing routines by introducing new, additional complexity. He is not recommending that anyone write obviously, ruinously slow, bloated code.
Writing software is an art and a science.
Optimization is no different. One frequently missing part of our process is to keep a watchful eye on features that are obviously toxic to performance during development (i.e., multiply-nested for loops, many large external dependencies, introducing and frequently iterating over huge, bloated structs, etc.).
As everyone says, measure early and often, but also please don't just shout "LEEEEEEEROY JENKINS!" as you throw fireballs of slow, bloated code into the world.
Re: Ask HN: How can I learn about performance optimization?
#127Please try to remember that one of the the most abused quotes in Software Engineering is the old Knuth chestnut about "Premature optimization is the root of all evil." The full quote is as follows, "Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and ma…
His books (linked on the blog post) are also incredible, concrete resources to learn about optimizing systems.
[1] https://www.brendangregg.com/blog/2021-06-04/an-unbelievable...
Re: Ask HN: How can I learn about performance optimization?
#128Earlier quoted context omitted.
Definitely still useful, but some info, esp on some C++ things, is already outdated or even wrong. But still a good resource if approached with "trust but verify" mindset
Excellent point. To be honest I've not approached the material in a few years. Can you pinpoint which areas are wrong?
For example, on page 36 he asserts: "Accessing a variable or object through a pointer or reference may be just as fast as accessing it directly." While this might be true for a large/compound object (neglecting non-cached memory access vs cached memory, such as the stack), this is certainly not true in general case for simple POD types, such as ints or floats, if a compiler can't prove that between accesses the variable hasn't been modified (which happens actually very frequently). I've seen x10 speedups of computations in tight loops when I explicitly cached a value used in the loop into a variable from under a pointer/reference.
On p65 he asserts: "Assume that a function opens a file in exclusive mode, and an error condition terminates the program before the file is closed. The file will remain locked after the program is terminated and the user will be unable to access the file until the computer is rebooted." This is just hilarious not at the last modified date 2023-07-01, but even two decades ago. This could be true in times of DOS and maybe Windows 3.11. I might not remember exactly, but I think even Windows 95 have already dealt with it by tracking resources acquired by a process, and releasing everything after process termination. All WindowsNT family definitely didn't/doesn't have this issue (unless your program is a kernel-mode driver, but I'm not even sure in that, since my knowledge of kernel mode is circa ~2007 at most).
And I could keep counting, this isn't all issues, unfortunately... So there's some historical interest in the document, but...one shouldn't trust it blindly for today's things.
Re: Ask HN: How can I learn about performance optimization?
#129Then optimize it - measure front end render performance/compilation times/code perf, and then do the same on the backend. Write a blog post about it.
No substitute for experience