The Runtime Theory
mediumHardwareInternals#explain-the-model#reason-about-tradeoffs

Explain Why Memory Locality Matters

Explain the model, execution steps, complexity, and limits of why memory locality matters.

TRT practice prompt — not a verified question from a named employer.

The Runtime Theory Team6 min read

Interview prompt

Explain why memory locality matters to an engineer who understands the surrounding system but has not used this technique. Walk from its contract to a concrete operation, then discuss where it fails or becomes expensive.

A strong answer

Processors use a hierarchy of storage because small, nearby storage can be accessed faster than large, distant storage. A cache keeps copies of recently or predictably used memory blocks. Programs benefit when accesses show temporal locality, reusing data, or spatial locality, touching nearby addresses.

A row-major matrix traversal that increments the inner column index typically consumes adjacent elements, while stepping through a column may jump by an entire row stride. The values are mathematically identical, but the second access pattern may fetch cache lines that contain mostly unused data.

A complete answer also calls out the assumptions that control correctness. A cache hit avoids a slower level; a miss fetches a block and may evict another useful block. Capacity, associativity, and line size shape conflict behavior. Caches improve typical access time but make performance depend on working-set size and access order.

Close by describing one representative test or measurement. Rewrite a matrix transpose loop so reads are contiguous. Then reason about the writes: why can optimizing one side still leave the other side with poor locality?

Follow-up questions

Answer the follow-ups in the frontmatter. Use the linked article for the concept and the trace to make the explanation concrete.

This answer walks

Practice follow-ups

  1. 01Which assumption is essential for the approach to be correct?
  2. 02What is the worst case, and how does it change the resource cost?
  3. 03How would you adapt the design if the input or workload became much larger?
  4. 04What boundary test would give you the most confidence in the implementation?

One dispatch a week

The trace behind each question, the tradeoff that explains it, and one technical dispatch per week — no noise.

One technical dispatch per week. No noise.

Not started

Sign in to save your learning progress.

Sign in to save