SlideShare a Scribd company logo
1 of 44
Download to read offline
Introduction to
Data-Oriented Design
@YaroslavBunyak	

Senior Software Engineer, SoftServe
Programming, M**********r	

Do you speak it?
Story
Sieve of Eratosthenes
1

2

3

4

5

6

7

8

9 10 11 12 13 14 15 16 17 18 19 20

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Sieve of Eratosthenes
1

2

3

4

5

6

7

8

9 10 11 12 13 14 15 16 17 18 19 20

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Sieve of Eratosthenes
1

2

3

4

5

6

7

8

9 10 11 12 13 14 15 16 17 18 19 20

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Sieve of Eratosthenes
1

2

3

4

5

6

7

8

9 10 11 12 13 14 15 16 17 18 19 20

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Sieve of Eratosthenes
1

2

3

4

5

6

7

8

9 10 11 12 13 14 15 16 17 18 19 20

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Sieve of Eratosthenes
1

2

3

4

5

6

7

8

9 10 11 12 13 14 15 16 17 18 19 20

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Sieve of Eratosthenes
1

2

3

4

5

6

7

8

9 10 11 12 13 14 15 16 17 18 19 20

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Sieve of Eratosthenes

Simple algorithm	

Easy to implement
Sieve of Eratosthenes
int array[SIZE];	

array[i] = 1;	

if (array[i]) ...	

!

int bits[SIZE / 32];	

bits[i / 32] |= 1 << (i % 32);	

if (bits[i / 32] & (1 << (i % 32))) ...
Sieve of Eratosthenes
Simple algorithm	

Easy to implement	

But...	

unexpected results
Sieve of Eratosthenes
The second implementation (bitset) is 3-5x
faster than first (array)	

Even though it actually does more work
Why?!.
Fast Forward
...
• Years have passed	

• I become a software engineer	

• And one day...
This Graph

CPU/Memory performance

Slide 17

Computer architecture: a quantitative approach
By John L. Hennessy, David A. Patterson, Andrea C. Arpaci-Dusseau
This Table
1980

Modern PC

Improvement, %

Clock speed, Mhz

6

3000

+500x

Memory size, MB

2

2000

+1000x

Memory bandwidth, MB/s

13

7000 (read)	

2000 (write)

+540x	

+150x

Memory latency, ns

225

~70

+3x

Memory latency, cycles

1.4

210

-150x
Memory Hierarchy
CPU

•
•
•
•
•

CPU registers	

Cache Level 1	

Cache Level 2	


L1i	

Cache

L1d	

Cache

L2	

Cache

RAM	

HDD

RAM

Disk
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 office, get
up out of the chair.	


http://hacksoflife.blogspot.com/2011/04/going-to-california-with-aching-in-my.html
Fact
• Memory access is expensive	

• CPU cycles are cheap
Modern Programming
• High-level languages and abstractions	

• OOP	

• everywhere!	

• objects scattered throughout the
address space	


• memory access patterns are
unpredictable
Meet
Data-Oriented Design
Ideas
• code transforms data	

• data >> code	

• hardware is not a black box
Program
data

xform

data
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	

};
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]);	

}
Example 1: AoS vs SoA
!
!
!
!
!
!
vs	


!
!
!
!
By The Way
• Memory loads in chunks, not single bytes	

• One such chunk is called a cache line	

• Typical size: 64 or 128 bytes
Example 1: AoS vs SoA
!
!
!
!
!
!
vs	


!
!
!
!
Example 2: Existence
struct Image	

{	

bool ready[SIZE];	

Data pixels[SIZE];	

};	

Image image;	

vs	

Data ready_pixels[N];	

// N ≤ SIZE	


!
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];	

}
Example 3: Locality
!
array<float> numbers;	

float sum = 0.0f;	

for (auto it : numbers)	

sum += *it;	


!
vs	

list<float> numbers;	

float sum = 0.0f;	

for (auto it : numbers)	

sum+ = *it;
Example 3: Locality
!
!
!
!
!
!
vs	


!
!
!
!
Advice
• Keep your data closer to registers and
cache (hot data)	


• Don’t touch what you don’t have to (cold
data)	


• Predictable access patterns (e.g. linear
arrays) - good	


• What’s good for memory - good for you
DOD Patterns
• A to B transform	

• In-place transform	

• Existence based processing	

• Data normalization	

• DB design says hello!	

• Task, gather, dispatch, and more...
DOD Benefits
• 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!
References: Memory
• Ulrich Drepper “What Every Computer

Programmer Should Know About Memory”	


• Крис Касперски “Техника оптимизации
програм. Еффективное использование
памяти”	


• Christer Ericson “Memory Optimization”	

• Igor Ostrovsky “Gallery of Processor Cache
Effects”
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”	

• Niklas Frykholm “Practical Examples of Data Oriented
Design”, also everything on http://bitsquid.blogspot.com/	


• Mike Acton “Typical C++ Bullshit”	

• Data Oriented Design @ Google+
Bonus: Object or not?
Q: What is a table?	

A: Flat top and 4 legs.	

Q: Object? (OOP)	

A:Yes.	

Q: If we remove one leg. Is it still an object?	

A: …	

DOD: There is no table :)
Bonus: Object or not?
Q:You are modelling a pile of sand. Is it an object?	

A:Yes.	

Q: What is the border line number of particles N after
which just a bunch of sand particles start forming a pile? 10?
1000? 1000000?	

(i.e. can we say that N particles are just a bunch of particles,
but N+1 particles become a pile of sand?)	

A: …	

DOD: Sand particles are data.
Thank You!
Q?

More Related Content

Viewers also liked

გიორგი კორნაპელი
გიორგი კორნაპელიგიორგი კორნაპელი
გიორგი კორნაპელიNino Chipashvili
 
Pcy coal presentation
Pcy coal presentationPcy coal presentation
Pcy coal presentationProphecy Corp
 
페이스북 타임라인 적용하기
페이스북 타임라인 적용하기페이스북 타임라인 적용하기
페이스북 타임라인 적용하기Yun Jeong Jang
 
Interview Assessment Guide : Chief Development Officer
Interview Assessment Guide : Chief Development OfficerInterview Assessment Guide : Chief Development Officer
Interview Assessment Guide : Chief Development Officerdsnigel5
 
Employing a transition management approach to discover a new role for the so...
Employing a transition management approachto discover a new role for the so...Employing a transition management approachto discover a new role for the so...
Employing a transition management approach to discover a new role for the so...Leen Gorissen
 
Iq' rum buku tulis
Iq' rum buku tulisIq' rum buku tulis
Iq' rum buku tulisShika Nara
 
The essentials of collaboration
The essentials of collaborationThe essentials of collaboration
The essentials of collaborationHidden Art
 
โรงเรียนบ้านบ่อหลวง
โรงเรียนบ้านบ่อหลวงโรงเรียนบ้านบ่อหลวง
โรงเรียนบ้านบ่อหลวงSroypret Na Nan
 
Training Sandvik Coromant
Training Sandvik CoromantTraining Sandvik Coromant
Training Sandvik Coromantttehnologie
 
Jane Carr on the 'Handmade at Fortnum's' Exhibition she curated, from the Hid...
Jane Carr on the 'Handmade at Fortnum's' Exhibition she curated, from the Hid...Jane Carr on the 'Handmade at Fortnum's' Exhibition she curated, from the Hid...
Jane Carr on the 'Handmade at Fortnum's' Exhibition she curated, from the Hid...Hidden Art
 
Pendidikan seni visual_tahun_4
Pendidikan seni visual_tahun_4Pendidikan seni visual_tahun_4
Pendidikan seni visual_tahun_4Shika Nara
 
Havinq september 2013
Havinq   september 2013Havinq   september 2013
Havinq september 2013havinq
 

Viewers also liked (20)

გიორგი კორნაპელი
გიორგი კორნაპელიგიორგი კორნაპელი
გიორგი კორნაპელი
 
Pcy coal presentation
Pcy coal presentationPcy coal presentation
Pcy coal presentation
 
페이스북 타임라인 적용하기
페이스북 타임라인 적용하기페이스북 타임라인 적용하기
페이스북 타임라인 적용하기
 
Interview Assessment Guide : Chief Development Officer
Interview Assessment Guide : Chief Development OfficerInterview Assessment Guide : Chief Development Officer
Interview Assessment Guide : Chief Development Officer
 
Employing a transition management approach to discover a new role for the so...
Employing a transition management approachto discover a new role for the so...Employing a transition management approachto discover a new role for the so...
Employing a transition management approach to discover a new role for the so...
 
Iq' rum buku tulis
Iq' rum buku tulisIq' rum buku tulis
Iq' rum buku tulis
 
The essentials of collaboration
The essentials of collaborationThe essentials of collaboration
The essentials of collaboration
 
โรงเรียนบ้านบ่อหลวง
โรงเรียนบ้านบ่อหลวงโรงเรียนบ้านบ่อหลวง
โรงเรียนบ้านบ่อหลวง
 
DELM
DELMDELM
DELM
 
Training Sandvik Coromant
Training Sandvik CoromantTraining Sandvik Coromant
Training Sandvik Coromant
 
Zb a z
Zb a zZb a z
Zb a z
 
Jane Carr on the 'Handmade at Fortnum's' Exhibition she curated, from the Hid...
Jane Carr on the 'Handmade at Fortnum's' Exhibition she curated, from the Hid...Jane Carr on the 'Handmade at Fortnum's' Exhibition she curated, from the Hid...
Jane Carr on the 'Handmade at Fortnum's' Exhibition she curated, from the Hid...
 
Sarangi 2
Sarangi 2Sarangi 2
Sarangi 2
 
Wiladuras instruqcia
Wiladuras instruqciaWiladuras instruqcia
Wiladuras instruqcia
 
2008 Q1 md&a
2008 Q1 md&a2008 Q1 md&a
2008 Q1 md&a
 
Chapitre 08
Chapitre 08Chapitre 08
Chapitre 08
 
Power point musicaid
Power point musicaidPower point musicaid
Power point musicaid
 
Pcy coal fact_sheet
Pcy coal fact_sheetPcy coal fact_sheet
Pcy coal fact_sheet
 
Pendidikan seni visual_tahun_4
Pendidikan seni visual_tahun_4Pendidikan seni visual_tahun_4
Pendidikan seni visual_tahun_4
 
Havinq september 2013
Havinq   september 2013Havinq   september 2013
Havinq september 2013
 

Similar to Introduction to Data-Oriented Design

The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...
The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...
The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...Philip Schwarz
 
Generic Framework for Knowledge Classification-1
Generic Framework  for Knowledge Classification-1Generic Framework  for Knowledge Classification-1
Generic Framework for Knowledge Classification-1Venkata Vineel
 
#GDC15 Code Clinic
#GDC15 Code Clinic#GDC15 Code Clinic
#GDC15 Code ClinicMike Acton
 
Erik Laurijssen at UX Antwerp Meetup - 31 October 2017
Erik Laurijssen at UX Antwerp Meetup - 31 October 2017Erik Laurijssen at UX Antwerp Meetup - 31 October 2017
Erik Laurijssen at UX Antwerp Meetup - 31 October 2017UX Antwerp Meetup
 
HYDSPIN Dec14 visual story telling
HYDSPIN Dec14 visual story tellingHYDSPIN Dec14 visual story telling
HYDSPIN Dec14 visual story tellingGramener
 
Cache presentation on Mapping and its types
Cache presentation on Mapping and its typesCache presentation on Mapping and its types
Cache presentation on Mapping and its typesEngr Kumar
 
realestate and MySQL devops melbourne
realestate and MySQL devops melbournerealestate and MySQL devops melbourne
realestate and MySQL devops melbournemysqldbahelp
 
Visual Intelligence @ IBS, Hyderabad
Visual Intelligence @ IBS, HyderabadVisual Intelligence @ IBS, Hyderabad
Visual Intelligence @ IBS, HyderabadGramener
 
Muhammad (S.A.W ) Ka Pakistan / Islam Aur Pakistan March 2013
Muhammad (S.A.W ) Ka Pakistan / Islam Aur Pakistan March 2013Muhammad (S.A.W ) Ka Pakistan / Islam Aur Pakistan March 2013
Muhammad (S.A.W ) Ka Pakistan / Islam Aur Pakistan March 2013islamiroohanimission
 
M1S2U1 (Counting to 120 by Tens and Ones)
M1S2U1 (Counting to 120 by Tens and Ones)M1S2U1 (Counting to 120 by Tens and Ones)
M1S2U1 (Counting to 120 by Tens and Ones)EA Clavel
 
Analyzing OS X Systems Performance with the USE Method
Analyzing OS X Systems Performance with the USE MethodAnalyzing OS X Systems Performance with the USE Method
Analyzing OS X Systems Performance with the USE MethodBrendan Gregg
 
MeetBSD2014 Performance Analysis
MeetBSD2014 Performance AnalysisMeetBSD2014 Performance Analysis
MeetBSD2014 Performance AnalysisBrendan Gregg
 

Similar to Introduction to Data-Oriented Design (20)

The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...
The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...
The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...
 
Generic Framework for Knowledge Classification-1
Generic Framework  for Knowledge Classification-1Generic Framework  for Knowledge Classification-1
Generic Framework for Knowledge Classification-1
 
#GDC15 Code Clinic
#GDC15 Code Clinic#GDC15 Code Clinic
#GDC15 Code Clinic
 
Unit 3 ca-memory
Unit 3 ca-memoryUnit 3 ca-memory
Unit 3 ca-memory
 
Erik Laurijssen at UX Antwerp Meetup - 31 October 2017
Erik Laurijssen at UX Antwerp Meetup - 31 October 2017Erik Laurijssen at UX Antwerp Meetup - 31 October 2017
Erik Laurijssen at UX Antwerp Meetup - 31 October 2017
 
HYDSPIN Dec14 visual story telling
HYDSPIN Dec14 visual story tellingHYDSPIN Dec14 visual story telling
HYDSPIN Dec14 visual story telling
 
Cache presentation
Cache presentationCache presentation
Cache presentation
 
Cache presentation on Mapping and its types
Cache presentation on Mapping and its typesCache presentation on Mapping and its types
Cache presentation on Mapping and its types
 
realestate and MySQL devops melbourne
realestate and MySQL devops melbournerealestate and MySQL devops melbourne
realestate and MySQL devops melbourne
 
Visual Intelligence @ IBS, Hyderabad
Visual Intelligence @ IBS, HyderabadVisual Intelligence @ IBS, Hyderabad
Visual Intelligence @ IBS, Hyderabad
 
Muhammad (S.A.W ) Ka Pakistan / Islam Aur Pakistan March 2013
Muhammad (S.A.W ) Ka Pakistan / Islam Aur Pakistan March 2013Muhammad (S.A.W ) Ka Pakistan / Islam Aur Pakistan March 2013
Muhammad (S.A.W ) Ka Pakistan / Islam Aur Pakistan March 2013
 
QCon London.pdf
QCon London.pdfQCon London.pdf
QCon London.pdf
 
3 computer basics
3 computer basics3 computer basics
3 computer basics
 
Prime numbers
Prime numbersPrime numbers
Prime numbers
 
Prime numbers
Prime numbersPrime numbers
Prime numbers
 
M1S2U1 (Counting to 120 by Tens and Ones)
M1S2U1 (Counting to 120 by Tens and Ones)M1S2U1 (Counting to 120 by Tens and Ones)
M1S2U1 (Counting to 120 by Tens and Ones)
 
THE BIGVIZ
THE BIGVIZTHE BIGVIZ
THE BIGVIZ
 
Analyzing OS X Systems Performance with the USE Method
Analyzing OS X Systems Performance with the USE MethodAnalyzing OS X Systems Performance with the USE Method
Analyzing OS X Systems Performance with the USE Method
 
Cadcamlecture 12
Cadcamlecture 12Cadcamlecture 12
Cadcamlecture 12
 
MeetBSD2014 Performance Analysis
MeetBSD2014 Performance AnalysisMeetBSD2014 Performance Analysis
MeetBSD2014 Performance Analysis
 

Recently uploaded

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 

Introduction to Data-Oriented Design

  • 4. Sieve of Eratosthenes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  • 5. Sieve of Eratosthenes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  • 6. Sieve of Eratosthenes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  • 7. Sieve of Eratosthenes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  • 8. Sieve of Eratosthenes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  • 9. Sieve of Eratosthenes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  • 10. Sieve of Eratosthenes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  • 11. Sieve of Eratosthenes Simple algorithm Easy to implement
  • 12. Sieve of Eratosthenes int array[SIZE]; array[i] = 1; if (array[i]) ... ! int bits[SIZE / 32]; bits[i / 32] |= 1 << (i % 32); if (bits[i / 32] & (1 << (i % 32))) ...
  • 13. Sieve of Eratosthenes Simple algorithm Easy to implement But... unexpected results
  • 14. Sieve of Eratosthenes The second implementation (bitset) is 3-5x faster than first (array) Even though it actually does more work
  • 17. ... • Years have passed • I become a software engineer • And one day...
  • 18. This Graph CPU/Memory performance Slide 17 Computer architecture: a quantitative approach By John L. Hennessy, David A. Patterson, Andrea C. Arpaci-Dusseau
  • 19. This Table 1980 Modern PC Improvement, % Clock speed, Mhz 6 3000 +500x Memory size, MB 2 2000 +1000x Memory bandwidth, MB/s 13 7000 (read) 2000 (write) +540x +150x Memory latency, ns 225 ~70 +3x Memory latency, cycles 1.4 210 -150x
  • 20. Memory Hierarchy CPU • • • • • CPU registers Cache Level 1 Cache Level 2 L1i Cache L1d Cache L2 Cache RAM HDD RAM Disk
  • 21. 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 office, get up out of the chair. http://hacksoflife.blogspot.com/2011/04/going-to-california-with-aching-in-my.html
  • 22. Fact • Memory access is expensive • CPU cycles are cheap
  • 23. Modern Programming • High-level languages and abstractions • OOP • everywhere! • objects scattered throughout the address space • memory access patterns are unpredictable
  • 25. Ideas • code transforms data • data >> code • hardware is not a black box
  • 27. 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 };
  • 28. 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]); }
  • 29. Example 1: AoS vs SoA ! ! ! ! ! ! vs ! ! ! !
  • 30. By The Way • Memory loads in chunks, not single bytes • One such chunk is called a cache line • Typical size: 64 or 128 bytes
  • 31. Example 1: AoS vs SoA ! ! ! ! ! ! vs ! ! ! !
  • 32. Example 2: Existence struct Image { bool ready[SIZE]; Data pixels[SIZE]; }; Image image; vs Data ready_pixels[N]; // N ≤ SIZE !
  • 33. 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]; }
  • 34. Example 3: Locality ! array<float> numbers; float sum = 0.0f; for (auto it : numbers) sum += *it; ! vs list<float> numbers; float sum = 0.0f; for (auto it : numbers) sum+ = *it;
  • 36. Advice • Keep your data closer to registers and cache (hot data) • Don’t touch what you don’t have to (cold data) • Predictable access patterns (e.g. linear arrays) - good • What’s good for memory - good for you
  • 37. DOD Patterns • A to B transform • In-place transform • Existence based processing • Data normalization • DB design says hello! • Task, gather, dispatch, and more...
  • 38. DOD Benefits • 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!
  • 39. References: Memory • Ulrich Drepper “What Every Computer Programmer Should Know About Memory” • Крис Касперски “Техника оптимизации програм. Еффективное использование памяти” • Christer Ericson “Memory Optimization” • Igor Ostrovsky “Gallery of Processor Cache Effects”
  • 40. 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” • Niklas Frykholm “Practical Examples of Data Oriented Design”, also everything on http://bitsquid.blogspot.com/ • Mike Acton “Typical C++ Bullshit” • Data Oriented Design @ Google+
  • 41. Bonus: Object or not? Q: What is a table? A: Flat top and 4 legs. Q: Object? (OOP) A:Yes. Q: If we remove one leg. Is it still an object? A: … DOD: There is no table :)
  • 42. Bonus: Object or not? Q:You are modelling a pile of sand. Is it an object? A:Yes. Q: What is the border line number of particles N after which just a bunch of sand particles start forming a pile? 10? 1000? 1000000? (i.e. can we say that N particles are just a bunch of particles, but N+1 particles become a pile of sand?) A: … DOD: Sand particles are data.
  • 44. Q?