Skip to content

Files

Latest commit

2674cb9 · Nov 11, 2021

History

History
This branch is 2 commits ahead of, 1130 commits behind iluwatar/java-design-patterns:master.

data-locality

README.md

layout title folder permalink categories language tags
pattern
Data Locality
data-locality
/patterns/data-locality/
Behavioral
en
Game programming
Performance

Intent

Accelerate memory access by arranging data to take advantage of CPU caching.

Modern CPUs have caches to speed up memory access. These can access memory adjacent to recently accessed memory much quicker. Take advantage of that to improve performance by increasing data locality keeping data in contiguous memory in the order that you process it.

Class diagram

alt text

Applicability

  • Like most optimizations, the first guideline for using the Data Locality pattern is when you have a performance problem.
  • With this pattern specifically, you’ll also want to be sure your performance problems are caused by cache misses.

Real world example

  • The Artemis game engine is one of the first and better-known frameworks that uses simple IDs for game entities.

Credits