by vvanders · 11y ago · 0 comments
Lastly the virtual call again has the chance to cache miss(although probably only once seeing as we've just got a few impls).
In a small example like this there's a good chance that most of the heap allocations are close together but put this approach into production and you can very easily see fragmentation start driving up your cache misses.
(FWIW I'd also store radius*radius on creation, use a BSP/kd-tree and all sorts of other tricks that really help in these types of computations).
# program time change
./ray-ml: 21.46 # Original ocaml
./ray-cpp: 17.63 # Original c++
./ray-cpp-no-dtor: 13.86 # Removed all cleanup, ocaml doesn't do it
./ray-cpp-2: 8.90 # Changed list to vector
./ray-cpp-3: 7.89 # Removed virtual functions
./ray-cpp-4: 5.64 # Preallocated large array for all GroupsIf there's one thing I could teach new CS-grads it's how much your memory access patterns(and cache) really-effing-matter. Everything else is almost noise in comparison.
It's certainly likely that I just didn't take the right kinds of classes, or that I did but just missed or failed to really internalize this, but I'm curious if something else is going on. Has the bottleneck increasingly become memory rather than CPU? Have we more thoroughly exhausted other areas of optimization?
I was thinking about this while watching a talk[0] given by someone from Google about data structures in the STL, which decried that the standardized specification for `std::unordered_map` more or less forces an implementation to use buckets instead of the more cache-friendly technique of probing. I'm sure that the people who standardized it were very competent, which makes me think that, at least at the time, buckets were thought to be the better implementation.
[0]: https://www.youtube.com/watch?v=fHNmRkzxHWs
Edit: Added video link.
Yes.
Besides the basic memory latency vs. CPU clock speed issue, there's also:
- CPU caches have gotten bigger, so the payoff of making an program cache-friendly is larger
- CPUs have gained SIMD vector ALUs and increased superscalar behavior, so the CPU is capable of processing more data in per clock cycle
- A cultural shift happened after the freewheeling Moore's Law era ended in the mid-2000s, and people started examining performance more closely
http://gec.di.uminho.pt/discip/minf/ac0102/1000gap_proc-mem_...