C++ Performance and Optimisation
summary
Starts with profiling to find silly hotspots then moves to concrete fixes: eliminate repeated allocations (malloc costs 200–500 cycles), collapse memcopies, use reserve to turn 25 allocations into 1 for a 10M-element vector, prefer move semantics to avoid copies, and separate hot/cold fields to get dense linear access for vectorization. Uses tooling like perf, valgrind cachegrind and Google Benchmark to measure cache misses, shows unordered_map vs map tradeoffs, and emphasizes memory bandwidth and cache layout as the dominant performance levers.
AI-written summary · about
chapters (23)
- 0:00Start
- 4:19The performance story
- 6:15Overview
- 8:05Donald Knuth, 1974 (premature optimization paper)
- 9:34Modem CPUs
- 13:46Instructions are "free", memory b/w isn't
- 15:32Cache hierarchy
- 20:57Performance tools
- 22:34Data layout and performance
- 24:34Vectorisation (2)
- 26:33Strength reduction
- 27:32Move semantics and value references
- 28:33Move semantics example
- 29:48Implementing move semantics
- 35:57Optimisation - hash function
- 37:37Domain knowledge
- 41:22Non-primary key access
- 42:22Range scans and sexuential access
- 43:50Read/write ratio
- 44:33Working set size
- 45:54Consistency
- 46:51Strings - implementation choices
- 57:38Summary
related talks
01h 00mMoving Faster: Everyday efficiency in modern C++
55mWriting Cache-Friendly C++
01h 00mCache Friendly C++
01h 05mFast and small C++ - When efficiency matters
01h 01mRefresher on Containers, Algorithms and Performance in C++
01h 11m“Benchmarking C++ Code"
01h 04mDesign for Performance
01h 01mFaster, Easier, Simpler Vectors
