If a memory location is referenced, it is very likely that the same location will be referenced again in the near future.
The goal here is to keep recently/frequently hot data in the L1 or L2 cache so it doesn’t have to be evicted and re-fetched from RAM later.
Good Temporal Locality: A loop that performs multiple operations on the same variable.
Example
for (int i = 0; i < N; ++i) { float val = data[i]; res1[i] = transform1(val); // 'val' is in L1 cache res2[i] = transform2(val); // 'val' is still in L1 cache}
Bad Temporal Locality: Large-scale passes over data that exceed cache size. If you have a 1GB dataset and you perform one full pass to “Add 1”, then a second full pass to “Multiply by 2”, the data from the first pass is long gone from the cache by the time the second pass starts. This is where Kernel Fusion (combining loops) helps.