Random vs. Sequential Access: The Latency Divide
Random memory access, characteristic of hash table probes or sparse matrix operations, can be orders of magnitude slower than sequential access in arrays due to the high cost of cache misses and main memory latency.
The top 3
- CPU Cache Miss: Random Access Costs 50-80x More Cycles: Accessing data not in the CPU cache (a cache miss) due to random memory patterns can be 50 to 80 times slower than a cache hit, often stalling the CPU for hundreds of cycles, significantly impacting performance.
- Linked Lists vs. Arrays: The Cache Locality Divide: Arrays store data contiguously, leveraging cache lines and hardware prefetching for fast sequential access, while linked lists scatter data, leading to frequent cache misses and drastically slower random access despite theoretical O(1) insertion at a known position.
- Storage Latency Gap: HDDs vs. SSDs vs. NVMe: The performance disparity between random and sequential access is most pronounced in HDDs (10-100x slower for random), significantly reduced in SATA SSDs (100-200 µs random read latency), and further minimized in NVMe SSDs (20-70 µs random read latency) due to their lack of mechanical parts and optimized protocols.
Sources
Open the full topic