3 ms·
It is useful in case where the hardware prefetcher is not helpful. That is, indirect memory access (e.g. graph traversal), constantly accessing different pages
by yvdriess 9y ago
It is useful in case where the hardware prefetcher is not helpful. That is, indirect memory access (e.g. graph traversal), constantly accessing different pages (eg column wise access of a matrix with >4k kB rows)
Howeve, finding the right perfetch distance is key. Too early and you wasted an instruction. Too late and your cache line might already be evicted, degrading performance. When perfetch instructions were introduced, unit prefetches were commonly fine. Now you should probably do a sweep to find an ideal value.
Prefer giving your optimising compiler a prefetch hint, it will be better at guessing the distance and be less architecture-dependant.
- evincarofautumn 9y agoYeah, speaking of graph traversal, when I was working on the Mono runtime performance team at Xamarin, it helped considerably in the garbage collector (SGen) when we added some manual prefetching to scanning the object graph, but it took a fair amount of benchmarking to find the sweet spot.