Live data from Hacker News

Ask HN: How can I learn about performance optimization?

news.ycombinator.com

51–60 of 153 posts

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

#51
For several years I have worked primarily with performance optimizations in the context of video games (and previously in the context of surgical simulation). This differs subtly from optimization in certain other areas, so I figured I'd add my own perspective to this already excellent comment section.

1. First and foremost: measure early, measure often. It's been said so often and it still needs repeating. In fact, the more you know about performance the easier it can be to fall into the trap of not measuring enough. Measuring will show exactly where you need to focus your efforts. It will also tell you without question whether your work has actually lead to an improvement, and to what degree.

2. The easiest way to make things go faster is to do less work. Use a more efficient algorithm, refactor code to eliminate unnecessary operations, move repeated work outside of loops. There are many flavours, but very often the biggest performance boosts are gained by simply solving the same problem through fewer instructions.

3. Understand the performance characteristics of your system. Is your application CPU bound, GPU compute bound, memory bound? If you don't know this you could make the code ten times as fast without gaining a single ms because the system is still stuck waiting for a memory transfer. On the flip side, if you know your system is busy waiting for memory, perhaps you can move computations to this spot to leverage this free work? This is particularly important in shader optimizations (latency hiding).

4. Solve a different problem! You can very often optimize your program by redefining your problem. Perhaps you are using the optimal algorithm for the problem as defined. But what does the end user really need? Often there are very similar but much easier problems which are equivalent for all practical purposes. Sometimes because the complexity lies in special cases which can be avoided or because there's a cheap approximation which gives sufficient accuracy. This happens especially often in graphics programming where the end goal is often to give an impression that you've calculated something.

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

#52
post #49

Agner Fog’s optimization manuals are pretty good https://www.agner.org/optimize/

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

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

#53
post #17

If you want to learn how to understand the performance of the whole system I can recommend Brendan Gregg's Systems Performance: Enterprise and the Cloud ( https://www.brendangregg.com/blog/2020-07-15/systems-perform... ). It is a good book that teaches a lot of basics and techniques and gives a good understanding of the impact different system components can have on performance.

I am so fascinated by how differently people interpreted this thread, really shows the diversity of computing and performance work. Here's a book about performance in the context of "enterprise and the cloud".

I've worked with performance optimizations for years, but never touched a network connection. Because for me it's all in the context of optimizing single player video games, which primarily leads to a focus on graphics programming and GPU performance.

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

#54
post #10
post #7

Denis Bakhvalov has some great resources for this: 1. His free course: https://products.easyperf.net/perf-ninja 2. His free book: https://book.easyperf.net/perf_book (the 2nd edition is being worked on right now and there's a draft on github: https://github.com/dendibakh/perf-book )

+1 for Denis! The book does a great job explaining both “what does it mean for a program to be optimal?” And “what do I type into my terminal to check the performance?” Of course, it doesn’t cover every possible performance trick. For that, I’d also recommend the Intel Optimization Manual and Johnny’s Software Lab.

> Johnny’s Software Lab.

Funny, I've just discovered them via a totally different route and read a few articles. Definitely good resource to learn more about low-level CPU code optimization.

Though OP doesn't say what are they interested in. GPU code optimization, for example, is totally different bonkers Universe :D

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

#55
Measure everything and be extremely critical. Be ready to challenge common and popular held assumptions.

Here is something I wrote about extreme performance in JavaScript that is discarded by most programmers because most people that program JavaScript professionally cannot really program.

https://github.com/prettydiff/wisdom/blob/master/performance...

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

#56

For several years I have worked primarily with performance optimizations in the context of video games (and previously in the context of surgical simulation). This differs subtly from optimization in certain other areas, so I figured I'd add my own perspective to this already excellent comment section. 1. First and foremost: measure early, measure often. It's been said so often and it still needs repeating. In fact,…

Note "faster" is not the only thing to optimize for, and it (wall clock time) is actually a bit unusual as it doesn't represent an exhaustible resource.

That is, if you have a rarely used slow part of the system, that might make it seem unimportant, but not if running it uses all the disk space or drains your phone battery.

Even if that doesn't happen, there are things you can optimize in the unimportant parts - you can optimize them getting out of the way of the rest of the system, like by having smaller code size and not stomping all over caches.

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

#57

Performance optimization covers a lot of topics, it depends on what you are trying to optimize. 1. Latency vs throughput. Oftentimes they are the same, i.e. reduce the time it takes to do something. However, when you passed a certain threshold, techniques that can optimize throughput will hurt latency, so it is important to know what you are looking for. There are also low level details if you have rather extreme lat…

> Latency vs throughput. Oftentimes they are the same Latency and thruput are never the same, they don't even have the same units so they can't be the same. Advice to OP. Learn how to make measurements, and you'll never make mistakes like these.

Please do read a bit about history of TCP and how latency impacts the overall throughout. It's a classic thing and applies to any processing where you need results of some steps to proceed.

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

#58

I really liked listening to and working on the projects of the open MIT course about performance https://ocw.mit.edu/courses/6-172-performance-engineering-of...

+1

I watched the lectures from 2018 on YouTube: https://m.youtube.com/playlist?list=PLUl4u3cNGP63VIBQVWguXxZ...

A big piece missing from there is algorithms and data structure, likely covered in one (or multiple) other course(s).

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

#59

For several years I have worked primarily with performance optimizations in the context of video games (and previously in the context of surgical simulation). This differs subtly from optimization in certain other areas, so I figured I'd add my own perspective to this already excellent comment section. 1. First and foremost: measure early, measure often. It's been said so often and it still needs repeating. In fact,…

Note "faster" is not the only thing to optimize for, and it (wall clock time) is actually a bit unusual as it doesn't represent an exhaustible resource. That is, if you have a rarely used slow part of the system, that might make it seem unimportant, but not if running it uses all the disk space or drains your phone battery. Even if that doesn't happen, there are things you can optimize in the unimportant parts - you…

> Note "faster" is not the only thing to optimize for

That is very true! I simply think of it first because it is often the biggest problem at my work. One of the extreme exceptions was optimising Wavetale for the Nintendo Switch, where we had to decrease memory usage from over 20GiB to below 3GiB.

> is actually a bit unusual as it doesn't represent an exhaustible resource.

Not in the context of game development, however! There you typically don't care about wall time. Instead, you work towards a set frame rate meaning you have a set slice of time (usually 16.7 or 33.3 ms) to go through the entire game and render loop each time.

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

#60

https://en.algorithmica.org/hpc/ This is a good book. It covers most common concepts and techniques in a fairly accessible way. At they end it also shows builds up a highly optimized version of some algorithms and data structures and does explains every optimization.

This is the answer. I have only read bits from this book, but it seems very good for what OP is looking for.
Post reply on HN