01

A chef and a distant pantry

A modern processor core can carry out several operations every clock cycle, billions of times a second. But each operation needs data, and the computer's main memory, its RAM, is far slower than the core. Fetching a value from RAM typically takes somewhere around 60 to 100 nanoseconds. At a clock speed of 4 gigahertz, one cycle lasts a quarter of a nanosecond, so an 80-nanosecond wait wastes about 320 cycles. Imagine a chef who can chop an onion in a second but must walk to a warehouse across town for each one. Cache is the countertop: a small space right beside the chef where the ingredients most likely needed next are kept.

02

Why small means fast

Cache is built from static RAM, which stores each bit in a cluster of about six transistors and can be read very quickly. Main memory uses dynamic RAM, storing each bit as charge in a tiny capacitor with one transistor: much denser and cheaper, but slower. Physics adds another limit. The bigger a memory, the longer its internal wires and the more time it takes to search. So designers build a hierarchy. Level-one cache, often tens of kilobytes per core, answers in a handful of cycles. Level two holds hundreds of kilobytes to a few megabytes. Level three, shared by all cores, may hold tens of megabytes and takes longer still.

03

Guessing what comes next

Cache works because programs are predictable in two ways. Temporal locality means data used once is likely to be used again soon, such as a counter in a loop. Spatial locality means data near something just used is likely to be needed next, such as the following entries in a list. To exploit both, caches store recent data and fetch memory in blocks called lines, usually 64 bytes. Read one number, and its neighbours arrive too. Hardware prefetchers go further, spotting patterns like a steady march through an array and fetching data before the program asks. When the needed data is already present, it is a hit; when not, it is a miss.

04

The arithmetic of hits

Small differences in hit rate have large effects. Suppose a cache answers in 1 nanosecond and main memory in 80. If 97 per cent of requests hit, the average access takes about 0.97 plus 0.03 times 80, roughly 3.4 nanoseconds. Drop the hit rate to 90 per cent and the average climbs to about 8.9 nanoseconds, more than twice as slow, although nine in ten requests still hit. That is why programmers working on games, databases and scientific software arrange data carefully. Processing items stored side by side can run many times faster than following pointers scattered randomly across memory, even when both approaches perform exactly the same number of calculations.

05

A growing share of the chip

The gap between processor speed and memory speed, sometimes called the memory wall, widened for decades as processors improved faster than RAM. Cache was the answer. IBM introduced one of the first commercial caches in its System/360 Model 85 in 1968. Early personal computer chips had none on board; modern processors devote a large share of their silicon to it. Some designs now stack an extra layer of cache directly on top of the processor die to add tens of megabytes. Keeping many caches consistent is its own challenge: when one core changes a value, the copies held by other cores must be updated or invalidated, governed by coherence protocols.

06

Why it matters to you

Cache size and design help explain why two processors with the same clock speed and core count can perform very differently, especially in games and large spreadsheets. It also matters for security. Because the time taken to read data reveals whether it was in cache, researchers showed in 2018 that attacks known as Spectre and Meltdown could use this timing to leak secrets between programs, forcing fixes across the industry. For buyers, cache is one of many specifications and best judged through real-world benchmarks rather than raw numbers. For engineers, it is a reminder that computing speed is often limited less by how fast a chip can calculate than by how quickly it can be fed.

FOLLOW THE EVIDENCE

Sources & further reading

Figures are rounded and widely published; check the linked organisations for the latest editions. These organisations do not endorse this website.