C's Contiguous Data: Cache Efficiency King

C arrays store elements contiguously in memory, enabling CPU cache prefetching and minimizing cache misses, which dramatically speeds up iterative data access compared to Python lists that store scattered pointers to individual, larger objects.

The top 3

  1. Cache Line Fill: Contiguous Data's Speed Multiplier: CPUs fetch memory in fixed-size cache lines, typically 64 bytes on modern processors; contiguous C arrays fully utilize these fetches, dramatically reducing main memory access latency compared to fragmented data.
  2. Spatial Locality: The Contiguous Data Performance King: Contiguous data structures maximize spatial locality, allowing the CPU to prefetch data efficiently and reducing cache misses, a key factor in speeding up array and matrix operations.
  3. Linked List vs. Array: Cache Misses' Performance Hit: Accessing elements in a linked list can be 10-100x slower than an array due to scattered memory locations leading to frequent cache misses, forcing the CPU to fetch data from much slower main memory.

Sources

Open the full topic