“Want fast C++? Know your hardware!"
summary
C++ performance depends on hardware patterns not just algorithms: traversing a 2D array in the wrong order gives about 30–40x slowdown on tested MacBooks; random indexing is random access >100x slower than linear scans despite identical work; cache lines (16/64 B) and associativity create 20x drops at power‑of‑two strides; unaligned accesses cost ~3x on older CPUs; sorting can expose branch‑predictor wins (MSVC shows ~6x), SIMD needs align to cache line, and denormals stall ~30x; benchmarks use clang/gcc/MSVC and Google Benchmark.
AI-written summary · about
chapters (15)
- 0:00Intro
- 4:36the rest of this talk
- 7:212d array traversal, 10 MB array
- 12:252d array traversal + some work
- 15:052D Array traversal: time profile Xcode Instruments
- 18:24temporal cache coherency
- 23:01accessing every Nth array element
- 24:58cache associativity
- 31:47unaligned memory access
- 33:15aligned vs. packed data access
- 40:05"harmless" branches
- 41:32virtual function calls
- 44:10sharing between cores
- 49:31data dependencies
- 55:08loop vectorisation - clang
related talks
01h 05mPerformance Optimization in Software Development - Being Friendly to Your Hardware
01h 02mSqueezing the Hardware to Make Performance Juice
01h 04mDesign for Performance
01h 00mMoving Faster: Everyday efficiency in modern C++
01h 01mRefresher on Containers, Algorithms and Performance in C++
48mC++ Algorithmic Complexity, Data Locality, Parallelism, Compiler Optimizations, & Some Concurrency
01h 00mCache Friendly C++
58mC++ Performance and Optimisation
