liveBook · Manning

Cache miss

As explained in High Performance Unity Game Development

A memory access in which the requested data is not found in a processor cache and must be retrieved from another memory level.

A cache miss occurs when requested data is absent from the CPU cache and must be retrieved from another memory level. In a game, moving an enemy can wait on its position, direction, and velocity: illustrative access times are 1–2 nanoseconds for L1 cache and 50–150 nanoseconds for main memory. section 1.2.2

Figure 1.7 Simplified example of how the CPU can access data in a system with three cache levels. If the data is not found in L1, the request continues to L2, then L3, and finally main memory. This example shows one possible cache-fill path; the exact behavior depends on the processor.

Illustrates one possible path from L1 through L2 and L3 to main memory; the exact behavior depends on the processor. section 1.2.2

To reduce misses, arrange data around what a workload processes together:

  • Keep related values close in memory. Because fetching data also brings in nearby data, the next needed values may already be cached. section 1.2.2
  • C# arrays of structs occupy a contiguous block, while arrays of classes hold addresses to objects that may be spread across the heap; these layouts differ in data locality. section 2.8

How High Performance Unity Game Development covers it

How deep it goes
Defines a miss and traces retrieval through cache levels to main memory, while noting that exact behavior depends on the processor.
Examples
Uses enemy position, direction, and velocity retrieval, plus contrasting C# arrays of structs and classes.
What you can do after
Evaluate data layouts by placing values processed together nearby to improve cache-hit likelihood.
How it connects
Connects cache misses to cache hits, data locality, data-oriented design, and heap allocation.

Also explained in

Compare how 4 books explain cache miss →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of High Performance Unity Game Development. The section links point to the parts of the book it draws on.