3 ms·
Learning about how the CPU cache works is probably the most useful thing you can do if you write anything that's not I/O limited. There are definitely a ton of
by TillE 3y ago
Learning about how the CPU cache works is probably the most useful thing you can do if you write anything that's not I/O limited. There are definitely a ton of experienced programmers who don't quite understand how often the CPU is just waiting around for data from RAM.
- arrowsmith 3y agoOkay, you've made me want to learn about it. Where do I start? What concepts do I need to understand? Any reading recommendations?
- Mockapapella 3y agoHaven't read through it, but I suspect this would be a good place to start: https://cpu.land/ https://cpu.land/ HN Discussion: https://news.ycombinator.com/item?id=36823605 https://news.ycombinator.com/item?id=36823605
- hayley-patton 3y agoDrepper's "What every programmer should know about memory", though you mightn't find it all interesting. https://gwern.net/doc/cs/hardware/2007-drepper.pdf https://gwern.net/doc/cs/hardware/2007-drepper.pdf
- mcculley 3y agoIt is a shame that there are not better monitoring tools that surface this. When I use Activity Monitor on macOS, it would be useful to see how much of “% CPU” is just waiting on memory. I know I can drill down with various profilers, but having it more accessible is way overdue.
- saagarjha 3y agoInstruments?
- sakras 3y agoInstruments is not nearly good enough for any serious performance work. Instruments only tells me what percent of time is spent in which part of the code. This is fine for a first pass, but it doesn’t tell me _why_ something is slow. I really need a V-Tune-like profiler on macOS.
- saagarjha 3y agoI’ve used it professionally and generally been happy with it. What are you missing from it?
- sakras 3y agoI’ve tried to use it professionally, but always end up switching to my x86 desktop to profile my code, just so I can use V-Tune. It’s missing any kind of deeper statistics such as memory bandwidth, cache misses, branch mispredictions, etc. I think fundamentally Apple is geared towards application development, whereas I’m working on more HPC-like things.
- saagarjha 3y agoHave you tried using the performance counters? They've been useful in my experience, although I don't touch them often. Instruments is definitely not geared towards this since most application developers rarely need to do profiling at this level, but it has some level of this built in when you need it.
- mcculley 3y agoDigging around in Instruments is the opposite of accessible. Every OS always had easy ways to tell if a process is waiting on disk or network (e.g., top, Activity Monitor). The mechanisms for measuring how often a process is waiting on memory exist, but you have to use profilers to use them. We are overdue to have them more accessible. Think of a column after “% CPU” that shows percentage of time blocked on memory.
- saagarjha 3y agoIt’s only useful once you understand how algorithmic complexity works, and how to profile your code, and how you language runtime does things. Before that your CPU cache is largely opaque and trying to peer into it is probably counterproductive.