The document provides an introduction to data-oriented design (DOD). It discusses how modern computer architectures have changed with memory latency now being the dominant factor over CPU speed. This has made the traditional object-oriented programming model focused on code inefficient. DOD is presented as an alternative paradigm that focuses on data transformations rather than objects. Key principles of DOD include keeping data close to CPU caches, processing data together in blocks, and separating data from code. Examples are given showing how DOD can improve performance and locality of reference. Benefits of DOD include maximum performance, ease of parallelization, and simpler code.
43. Our Programming
Model
⢠High-level languages
⢠OOP
⢠everywhere!
⢠objects scattered throughout the
address space
⢠access patterns are unpredictable
61. Distance Metaphor
â˘
â˘
L1 cache: it's on your desk, pick it up.
L2 cache: it's on the bookshelf in your ofďŹce, get
up out of the chair.
62. Distance Metaphor
â˘
â˘
L1 cache: it's on your desk, pick it up.
â˘
Main memory: it's on the shelf in your garage
downstairs, might as well get a snack while you're
down there.
L2 cache: it's on the bookshelf in your ofďŹce, get
up out of the chair.
63. Distance Metaphor
â˘
â˘
L1 cache: it's on your desk, pick it up.
â˘
Main memory: it's on the shelf in your garage
downstairs, might as well get a snack while you're
down there.
â˘
Disk: it's in, um, California. Walk there. Walk back.
Really.
L2 cache: it's on the bookshelf in your ofďŹce, get
up out of the chair.
64. Distance Metaphor
â˘
â˘
L1 cache: it's on your desk, pick it up.
â˘
Main memory: it's on the shelf in your garage
downstairs, might as well get a snack while you're
down there.
â˘
Disk: it's in, um, California. Walk there. Walk back.
Really.
L2 cache: it's on the bookshelf in your ofďŹce, get
up out of the chair.
http://hacksoďŹife.blogspot.com/2011/04/going-to-california-with-aching-in-my.html
67. Advice
⢠Keep your data closer to registers and
cache
⢠Whatâs good for memory - good for you
68. Example 1: AoS vs SoA
struct Tile
{
bool ready;
Data pixels; // big chunk of data
};
Tile tiles[SIZE];
vs
struct Image
{
bool ready[SIZE];
// hot data
Data pixels[SIZE]; // cold data
};
69. Example 1: AoS vs SoA
for (int i = 0; i < SIZE; ++i)
{
if (tiles[i].ready)
draw(tiles[i].pixels);
}
vs
for (int i = 0; i < SIZE; ++i)
{
if (image.ready[i])
draw(image.pixels[i]);
}
71. Example 2: Existence
struct Image
{
bool ready[SIZE];
Data pixels[SIZE];
};
Image image;
vs
Data ready_pixels[N];
Data no_pixels[M];
// N + M = SIZE
72. Example 2: Existence
for (int i = 0; i < SIZE; ++i)
{
if (image.ready[i])
draw(image.pixels[i]);
}
vs
for (int i = 0; i < N; ++i)
{
draw(ready_pixels[i];
}
73. Example 3: Locality
std::vector<ďŹoat> numbers;
ďŹoat sum = 0.0f;
for (auto it : numbers)
sum += *it;
vs
std::list<ďŹoat> numbers;
ďŹoat sum = 0.0f;
for (auto it : numbers)
sum+ = *it;
75. Few Patterns
⢠A to B transform
⢠In place transform
⢠Existence based processing
⢠Data normalization
⢠DB design says hello!
⢠Task, gather, dispatch, and more...
78. BeneďŹts of DOD
â˘
â˘
Maximum performance
â˘
CPU doesnât wait & starve
Easy to parallelize
â˘
â˘
data is grouped, transforms separated
ready for Parallel Processing, OOP doesnât
79. BeneďŹts of DOD
â˘
â˘
â˘
Maximum performance
â˘
CPU doesnât wait & starve
Easy to parallelize
â˘
â˘
data is grouped, transforms separated
ready for Parallel Processing, OOP doesnât
Simpler code
â˘
surprise!
80. References: Memory
⢠Ulrich Drepper âWhat Every Computer
Programmer Should Know About Memoryâ
⢠ĐŃĐ¸Ń ĐĐ°ŃпоŃŃки âĐ˘ĐľŃ Đ˝Đ¸ĐşĐ° ОпŃиПиСаŃии
ĐżŃОгŃĐ°Đź. ĐŃŃокŃивнОо иŃпОНŃСОванио
паПŃŃиâ
⢠Christer Ericson âMemory Optimizationâ
⢠Igor Ostrovsky âGallery of Processor Cache
Effectsâ
81. References: DOD
â˘
Noel Llopis âData-Oriented Designâ, Game Developer
Magazine, September 2009
â˘
Richard Fabian âData-Oriented Desingâ, book draft
http://www.dataorienteddesign.com/dodmain/
â˘
â˘
Tony Albrecht âPitfalls of Object-Oriented Programmingâ
â˘
â˘
Mike Acton âTypical C++ Bullshitâ
Niklas Frykholm âPractical Examples of Data Oriented
Designâ
Data Oriented Design @ Google+