Cache Friendly C++
summary
Claim: use std::vector by default because contiguous storage beats pointer chasing. Concrete evidence: benchmarks on Apple M1 show RAM ~70 GB/s, L1 ~64–128 KB (≈3 cycles), L2 ≈8–12 MB (≈18 cycles), main memory adds ~100 ns and you hit cliffs near 2–4 MB. Surprises: sorted vector often outperforms unordered_map; random versus sequential access differs dramatically; false sharing kills multithreaded scaling. Tools and remedies: measure with perf, prefer open addressing hash tables, consider flat_map or hive, reorder fields and pad to cache line (64/128 B).
AI-written summary · about
chapters (19)
- 0:00Introduction
- 2:49Cache friendly C++ matters
- 4:53CPU caches and cache misses
- 11:18Smaller data types
- 16:35Bit fields and struct reordering
- 21:51Cache lines and prefetching
- 26:04Cache friendly containers
- 29:51Instruction caches and code layout
- 33:19Data vs object oriented design
- 39:36Caches and multi-threaded performance
- 46:45Summary
- 48:52Q&A
- 50:37Cache line sizes
- 52:00SOA vs AOS design
- 53:47Tools for cache analysis
- 54:28Pointer flag optimization
- 56:54Data oriented design applications
- 57:58Pointer authentication and cache tricks
- 58:39Cache friendly code across CPUs
related talks
55mWriting Cache-Friendly C++
58mC++ Performance and Optimisation
01h 01mFaster, Easier, Simpler Vectors
01h 01mRefresher on Containers, Algorithms and Performance in C++
01h 00mMoving Faster: Everyday efficiency in modern C++
01h 00m“Want fast C++? Know your hardware!"
01h 01mWhat do you mean by "Cache Friendly"?
01h 02mCache-friendly Design in Robot Path Planning with C++
