Pointer Chasing: The Ultimate Cache Killer

Data structures that rely heavily on pointers to non-contiguous memory locations, such as linked lists and many graph implementations, force the CPU to 'chase' pointers, resulting in highly irregular access and severe cache miss penalties.

The top 3

  1. 3 Data Structures Most Devastated by Pointer Chasing: Linked lists, binary search trees (especially unbalanced ones), and hash tables using separate chaining are notorious for generating cache misses due to their non-contiguous data access patterns and sequential memory dependencies.
  2. Top 3 Strategies to Combat Pointer Chasing Performance Hits: Employing Data-Oriented Design (DOD), transforming array-of-structs to struct-of-arrays, and utilizing memory pooling or arena allocation are key techniques to improve data locality and reduce cache misses.
  3. CPU-Memory Speed Gap: The Core Reason for Pointer Chasing's Impact: The ever-widening disparity between CPU clock speeds and DRAM latency, a trend accelerating since the 1980s, is the fundamental reason pointer chasing becomes a killer, forcing the CPU to stall for hundreds of cycles during cache misses.

Sources

Open the full topic