Live data from Hacker News

Ask HN: How can I learn about performance optimization?

news.ycombinator.com

131–140 of 153 posts

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

#132

What you really want to learn about is observability, benchmarking and instrumentation. Once you are an expert in these topics for your domain, optimization will be about making obvious choices within localized constraints.

Yes and no. I would agree that observability is the place to start. But knowing what needs to be optimized doesn't necessarily mean you know how to optimize it.

Also, while premature optimization is obviously a problem, knowing more about how to actually write optimized code can help you make more informed decisions earlier on in the development process.

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

#133
>What are some good resources for learning about performance optimization?

I swear, nobody actually read OP's post. The top five comments are "here's some personal advice about general rules of thumb, without any links to actual resources!"

Kudos to levodelellis, whose post is at #6 root comment and contain some links and drops some names.

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

#134
post #76

Former HFT dev here. Know fundamentals: sources of performance issues = things that eat/waste CPU cycles, things that reach too far down the memory hierarchy. Usually the latter. E.g. L2 cache to RAM - order of magnitude slower; RAM to disk: 4+ orders of magnitude slower. Things that eat CPU: iterations, string operations. Things that waste CPU: lock contentions in multi-threaded environments, wait states. You can us…

Can you suggest/recommend some books to learn these things in depth?

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

#135
post #30

If you're new to this area, I would first start by understanding which profiling tools you can use depending on the OS, languages and systems involved. Even if your system is not C++, I've always enjoyed this talk and the subsequent discussion which tackles some of the problems associated with some programming practices and the impact on performance. CppCon 2014: Mike Acton 'Data-Oriented Design and C++' https://yout…

I was just going to suggest that talk! Data locality is arguably the most important thing to consider when writing CPU intensive applications.

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

#136
post #128
post #95

Earlier quoted context omitted.

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…

> 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.

This is indeed an important gotcha! Let's say you have a filter and want to process an array of floats. If the coefficient is a struct member and has the same type as the audio samples, you must cache it in a local variable, otherwise the compiler might reload it from memory on every loop iteration. ('restrict' can somewhat help with these kind of aliasing issues, but you need to be careful.)

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

#137

Casey Muratori did many lectures. Check out his yt page playlist. Start with the one titled software quality https://www.youtube.com/@MollyRocket/playlists I heard good things about his course https://www.computerenhance.com/ Agner Fog manuals are good too https://www.agner.org/optimize/#manuals A site to look up instruction timings is https://uops.info/table.html

Can't praise Casey's course enough!

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

#138

>What are some good resources for learning about performance optimization? I swear, nobody actually read OP's post. The top five comments are "here's some personal advice about general rules of thumb, without any links to actual resources!" Kudos to levodelellis, whose post is at #6 root comment and contain some links and drops some names.

[deleted]

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

#139
post #76

Former HFT dev here. Know fundamentals: sources of performance issues = things that eat/waste CPU cycles, things that reach too far down the memory hierarchy. Usually the latter. E.g. L2 cache to RAM - order of magnitude slower; RAM to disk: 4+ orders of magnitude slower. Things that eat CPU: iterations, string operations. Things that waste CPU: lock contentions in multi-threaded environments, wait states. You can us…

Can you suggest/recommend some books to learn these things in depth?

Systems Performance: Enterprise and the Cloud, 2nd Edition (2020)

https://www.brendangregg.com/systems-performance-2nd-edition...

Post reply on HN