Live data from Hacker News

Ask HN: How can I learn about performance optimization?

news.ycombinator.com

121–130 of 153 posts

Re: Ask HN: How can I learn about performance optimization?

#123
Google publishes some of its data center optimization lessons and tips at http://abseil.io/fast. This includes topics like higher-level methodology and goal setting, these topics are often less covered by other resources.

Full disclosure: I'm the editor in chief for the series.

Re: Ask HN: How can I learn about performance optimization?

#124

One 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…

I'd add an addendum - look for stuff you don't need to do (e.g. at a low-level can you avoid that memcpy, zeroing things or multiple allocations when one would do, but even better at a high-level if you can avoid doing the whole thing altogether). It's better to just not do it rather than spends time trying to optimize it.

Re: Ask HN: How can I learn about performance optimization?

#126
Please 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 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?

#127

Please 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…

Also, there's another post trending on this very day from Brendan Gregg [1].

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?

#128
post #95
post #52

Earlier 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?

My biggest concern is his "Optimizing software in C++" (Copyright © 2004 - 2023. Last updated 2023-07-01 - so it's claimed to be quite "fresh") [ https://agner.org/optimize/optimizing_cpp.pdf ]. Some things could be attributed to just bad wording, but some... IMO, either don't tell all the truth, or tell outright wrong things. For example,

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?

#129
Write a piece of software in a week - a full app, with discrete functionality that would challenge you to deliver on time. Do it, and burn through it.

Then 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

Post reply on HN