SlideShare une entreprise Scribd logo
1  sur  77
Introduction to Data-Oriented Design
So what is this Data-Oriented Design?
It’s about on shifting focus to how data is read and written
Why should we care?
Performance
A read from memory takes ~600 cycles at 3.2 GHz
A read from memory takes 40 cycles at 300 MHz
Performance Disks (Blu-ray/DVD/HDD) Main Memory L2 Cache L1 Cache CPU / Registers Latency :( 600 cycles 40 cycles 1 – 2 cycles
Multithreading ,[object Object],[object Object],Object Read? Write? Object update() Object Read? Write? Read? Write?
Offloading to co-unit ,[object Object],? SPU/GPU/APU ?
Better design ,[object Object],[object Object]
Example - OOD class Bot { ... Vec3 m_position; ... float m_mod; ... float m_aimDirection; ... void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } }
Example - OOD class Bot { ... Vec3 m_position; ... float m_mod; ... float m_aimDirection; ... void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } } icache-miss
Example - OOD class Bot { ... Vec3 m_position; ... float m_mod; ... float m_aimDirection; ... void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } } icache-miss data-miss
Example - OOD class Bot { ... Vec3 m_position; ... float m_mod; ... float m_aimDirection; ... void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } } icache-miss data-miss Unused cached data
Example - OOD class Bot { ... Vec3 m_position; ... float m_mod; ... float m_aimDirection; ... void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } } icache-miss data-miss Unused cached data Very hard to optimize!
Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots)
Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600
Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600 m_position – 600
Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600 m_position – 600 m_mod - 600
Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600 m_position – 600 m_mod - 600 ~20 cycles
Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 ~20 cycles
Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 ~20 cycles iCache – 600 m_position – 600 m_mod - 600 aimDir – 100
Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 ~20 cycles iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 iCache – 600 m_position – 600 m_mod - 600 aimDir – 100
Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 ~20 cycles iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 iCache – 600 m_position – 600 m_mod - 600 aimDir – 100
Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 ~20 cycles iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 7680
Example - DOD
Example - DOD ,[object Object]
Example - DOD ,[object Object],[object Object]
Example - DOD void updateAims(float* aimDir,const AimingData* aim,   Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i],target) * aim->mod[i]; } }
Example - DOD void updateAims(float* aimDir,const AimingData* aim,   Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i],target) * aim->mod[i]; } } What has changed?
Example - DOD void updateAims(float* aimDir,const AimingData* aim,   Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i],target) * aim->mod[i]; } } Only read needed inputs What has changed?
Example - DOD void updateAims(float* aimDir,const AimingData* aim,   Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i],target) * aim->mod[i]; } } Only read needed inputs Write to linear array What has changed?
Example - DOD void updateAims(float* aimDir,const AimingData* aim,   Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i],target) * aim->mod[i]; } } Only read needed inputs Write to linear array Loop over all the data What has changed?
Example - DOD void updateAims(float* aimDir,const AimingData* aim,   Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i],target) * aim->mod[i]; } } Only read needed inputs Write to linear array Loop over all the data Actual code unchanged What has changed?
Example - DOD void updateAims(float* aimDir,const AimingData* aim,   Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i],target) * aim->mod[i]; } } Only read needed inputs Write to linear array Loop over all the data Actual code unchanged What has changed? Code separated
Example - DOD void updateAims(float* aimDir, const AimingData* aim,  Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } }
Example - DOD void updateAims(float* aimDir, const AimingData* aim,  Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600
Example - DOD void updateAims(float* aimDir, const AimingData* aim,  Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600 positions – 600
Example - DOD void updateAims(float* aimDir, const AimingData* aim,  Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600 positions – 600 mod - 600
Example - DOD void updateAims(float* aimDir, const AimingData* aim,  Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600 positions – 600 mod - 600 ~20 cycles
Example - DOD void updateAims(float* aimDir, const AimingData* aim,  Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600 positions – 600 mod - 600 aimDir – 100 ~20 cycles
Example - DOD void updateAims(float* aimDir, const AimingData* aim,  Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600 positions – 600 mod - 600 aimDir – 100 ~20 cycles
Example - DOD void updateAims(float* aimDir, const AimingData* aim,  Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600 positions – 600 mod - 600 aimDir – 100 ~20 cycles
Example - DOD void updateAims(float* aimDir, const AimingData* aim,  Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600 positions – 600 mod - 600 aimDir – 100 ~20 cycles
Example - DOD void updateAims(float* aimDir, const AimingData* aim,  Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600 positions – 600 mod - 600 aimDir – 100 ~20 cycles 1980
Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0
Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one  128 byte cache line
Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one  128 byte cache line
Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one  128 byte cache line
Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one  128 byte cache line
Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one  128 byte cache line
Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one  128 byte cache line
Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one  128 byte cache line
Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one  128 byte cache line
Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one  128 byte cache line
Its all about memory
Its all about memory ,[object Object]
Its all about memory ,[object Object],[object Object]
Its all about memory ,[object Object],[object Object],[object Object]
Remember
Remember ,[object Object]
Remember ,[object Object],[object Object]
Example: Area Triggers
Example: Area Triggers position position position position next position position position position next position position position position next Source data  (Linked List)
Example: Area Triggers position position position position next position position position position next position position position position next Source data  (Linked List) Native Data  (Array) position position position position position position position position position position position position position position count
Example: Culling System
Example: Culling System Old System
Example: Culling System Old System New System (Linear arrays and brute force)
Example: Culling System Old System New System (Linear arrays and brute force) 3x faster, 1/5 code size, simpler
Data Oriented Design Delivers:
Better Performance
Often simpler code
More parallelizable code
Questions?
Links ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Image credits ,[object Object],[object Object],[object Object],[object Object]

Contenu connexe

Tendances

송창규, unity build로 빌드타임 반토막내기, NDC2010
송창규, unity build로 빌드타임 반토막내기, NDC2010송창규, unity build로 빌드타임 반토막내기, NDC2010
송창규, unity build로 빌드타임 반토막내기, NDC2010
devCAT Studio, NEXON
 
Oit And Indirect Illumination Using Dx11 Linked Lists
Oit And Indirect Illumination Using Dx11 Linked ListsOit And Indirect Illumination Using Dx11 Linked Lists
Oit And Indirect Illumination Using Dx11 Linked Lists
Holger Gruen
 
Windows system - memory개념잡기
Windows system - memory개념잡기Windows system - memory개념잡기
Windows system - memory개념잡기
ChangKyu Song
 

Tendances (20)

게임서버프로그래밍 #1 - IOCP
게임서버프로그래밍 #1 - IOCP게임서버프로그래밍 #1 - IOCP
게임서버프로그래밍 #1 - IOCP
 
Triangle Visibility buffer
Triangle Visibility bufferTriangle Visibility buffer
Triangle Visibility buffer
 
Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기
 
[야생의 땅: 듀랑고] 서버 아키텍처 Vol. 2 (자막)
[야생의 땅: 듀랑고] 서버 아키텍처 Vol. 2 (자막)[야생의 땅: 듀랑고] 서버 아키텍처 Vol. 2 (자막)
[야생의 땅: 듀랑고] 서버 아키텍처 Vol. 2 (자막)
 
Siggraph2016 - The Devil is in the Details: idTech 666
Siggraph2016 - The Devil is in the Details: idTech 666Siggraph2016 - The Devil is in the Details: idTech 666
Siggraph2016 - The Devil is in the Details: idTech 666
 
송창규, unity build로 빌드타임 반토막내기, NDC2010
송창규, unity build로 빌드타임 반토막내기, NDC2010송창규, unity build로 빌드타임 반토막내기, NDC2010
송창규, unity build로 빌드타임 반토막내기, NDC2010
 
ECS (Part 1/3) - Introduction to Data-Oriented Design
ECS (Part 1/3) - Introduction to Data-Oriented DesignECS (Part 1/3) - Introduction to Data-Oriented Design
ECS (Part 1/3) - Introduction to Data-Oriented Design
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
 
Data-Oriented Design과 유니티 DOTS
Data-Oriented Design과 유니티 DOTSData-Oriented Design과 유니티 DOTS
Data-Oriented Design과 유니티 DOTS
 
Entity Component Systems
Entity Component SystemsEntity Component Systems
Entity Component Systems
 
Windows Registered I/O (RIO) vs IOCP
Windows Registered I/O (RIO) vs IOCPWindows Registered I/O (RIO) vs IOCP
Windows Registered I/O (RIO) vs IOCP
 
Vulkan 1.1 Reference Guide
Vulkan 1.1 Reference GuideVulkan 1.1 Reference Guide
Vulkan 1.1 Reference Guide
 
Sql query patterns, optimized
Sql query patterns, optimizedSql query patterns, optimized
Sql query patterns, optimized
 
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
 
Iocp 기본 구조 이해
Iocp 기본 구조 이해Iocp 기본 구조 이해
Iocp 기본 구조 이해
 
Screen Space Decals in Warhammer 40,000: Space Marine
Screen Space Decals in Warhammer 40,000: Space MarineScreen Space Decals in Warhammer 40,000: Space Marine
Screen Space Decals in Warhammer 40,000: Space Marine
 
Oit And Indirect Illumination Using Dx11 Linked Lists
Oit And Indirect Illumination Using Dx11 Linked ListsOit And Indirect Illumination Using Dx11 Linked Lists
Oit And Indirect Illumination Using Dx11 Linked Lists
 
[NDC 2018] 신입 개발자가 알아야 할 윈도우 메모리릭 디버깅
[NDC 2018] 신입 개발자가 알아야 할 윈도우 메모리릭 디버깅[NDC 2018] 신입 개발자가 알아야 할 윈도우 메모리릭 디버깅
[NDC 2018] 신입 개발자가 알아야 할 윈도우 메모리릭 디버깅
 
Fluentd with MySQL
Fluentd with MySQLFluentd with MySQL
Fluentd with MySQL
 
Windows system - memory개념잡기
Windows system - memory개념잡기Windows system - memory개념잡기
Windows system - memory개념잡기
 

En vedette

En vedette (15)

Technical direction
Technical directionTechnical direction
Technical direction
 
A Real-time Radiosity Architecture
A Real-time Radiosity ArchitectureA Real-time Radiosity Architecture
A Real-time Radiosity Architecture
 
Battlelog - Building scalable web sites with tight game integration
Battlelog - Building scalable web sites with tight game integrationBattlelog - Building scalable web sites with tight game integration
Battlelog - Building scalable web sites with tight game integration
 
SPU-Based Deferred Shading in BATTLEFIELD 3 for Playstation 3
SPU-Based Deferred Shading in BATTLEFIELD 3 for Playstation 3SPU-Based Deferred Shading in BATTLEFIELD 3 for Playstation 3
SPU-Based Deferred Shading in BATTLEFIELD 3 for Playstation 3
 
How data rules the world: Telemetry in Battlefield Heroes
How data rules the world: Telemetry in Battlefield HeroesHow data rules the world: Telemetry in Battlefield Heroes
How data rules the world: Telemetry in Battlefield Heroes
 
Stylized Rendering in Battlefield Heroes
Stylized Rendering in Battlefield HeroesStylized Rendering in Battlefield Heroes
Stylized Rendering in Battlefield Heroes
 
5 Major Challenges in Interactive Rendering
5 Major Challenges in Interactive Rendering5 Major Challenges in Interactive Rendering
5 Major Challenges in Interactive Rendering
 
Destruction Masking in Frostbite 2 using Volume Distance Fields
Destruction Masking in Frostbite 2 using Volume Distance FieldsDestruction Masking in Frostbite 2 using Volume Distance Fields
Destruction Masking in Frostbite 2 using Volume Distance Fields
 
Scope Stack Allocation
Scope Stack AllocationScope Stack Allocation
Scope Stack Allocation
 
Shadows & Decals: D3D10 Techniques in Frostbite (GDC'09)
 	 Shadows & Decals: D3D10 Techniques in Frostbite (GDC'09) 	 Shadows & Decals: D3D10 Techniques in Frostbite (GDC'09)
Shadows & Decals: D3D10 Techniques in Frostbite (GDC'09)
 
Bending the Graphics Pipeline
Bending the Graphics PipelineBending the Graphics Pipeline
Bending the Graphics Pipeline
 
Building the Battlefield AI Experience
Building the Battlefield AI ExperienceBuilding the Battlefield AI Experience
Building the Battlefield AI Experience
 
Stable SSAO in Battlefield 3 with Selective Temporal Filtering
Stable SSAO in Battlefield 3 with Selective Temporal FilteringStable SSAO in Battlefield 3 with Selective Temporal Filtering
Stable SSAO in Battlefield 3 with Selective Temporal Filtering
 
Future Directions for Compute-for-Graphics
Future Directions for Compute-for-GraphicsFuture Directions for Compute-for-Graphics
Future Directions for Compute-for-Graphics
 
Level Design Challenges & Solutions - Mirror's Edge
Level Design Challenges & Solutions - Mirror's EdgeLevel Design Challenges & Solutions - Mirror's Edge
Level Design Challenges & Solutions - Mirror's Edge
 

Similaire à Introduction to Data Oriented Design

Data oriented design
Data oriented designData oriented design
Data oriented design
Max Klyga
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
akaptur
 
Advance features of C++
Advance features of C++Advance features of C++
Advance features of C++
vidyamittal
 
Cppt 101102014428-phpapp01
Cppt 101102014428-phpapp01Cppt 101102014428-phpapp01
Cppt 101102014428-phpapp01
Getachew Ganfur
 
! Modernizr v2.0.6 httpwww.modernizr.com Copyri.docx
!  Modernizr v2.0.6  httpwww.modernizr.com   Copyri.docx!  Modernizr v2.0.6  httpwww.modernizr.com   Copyri.docx
! Modernizr v2.0.6 httpwww.modernizr.com Copyri.docx
MARRY7
 
New Features of SQL Server 2016
New Features of SQL Server 2016New Features of SQL Server 2016
New Features of SQL Server 2016
Mir Mahmood
 

Similaire à Introduction to Data Oriented Design (20)

Data oriented design
Data oriented designData oriented design
Data oriented design
 
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Cocos2d Performance Tips
Cocos2d Performance TipsCocos2d Performance Tips
Cocos2d Performance Tips
 
ParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdf
 
COW
COWCOW
COW
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
Hot Code is Faster Code - Addressing JVM Warm-up
Hot Code is Faster Code - Addressing JVM Warm-upHot Code is Faster Code - Addressing JVM Warm-up
Hot Code is Faster Code - Addressing JVM Warm-up
 
Improving Android Performance at Mobiconf 2014
Improving Android Performance at Mobiconf 2014Improving Android Performance at Mobiconf 2014
Improving Android Performance at Mobiconf 2014
 
Advance features of C++
Advance features of C++Advance features of C++
Advance features of C++
 
Cppt 101102014428-phpapp01
Cppt 101102014428-phpapp01Cppt 101102014428-phpapp01
Cppt 101102014428-phpapp01
 
Arrry structure Stacks in data structure
Arrry structure Stacks  in data structureArrry structure Stacks  in data structure
Arrry structure Stacks in data structure
 
! Modernizr v2.0.6 httpwww.modernizr.com Copyri.docx
!  Modernizr v2.0.6  httpwww.modernizr.com   Copyri.docx!  Modernizr v2.0.6  httpwww.modernizr.com   Copyri.docx
! Modernizr v2.0.6 httpwww.modernizr.com Copyri.docx
 
JVM code reading -- C2
JVM code reading -- C2JVM code reading -- C2
JVM code reading -- C2
 
Jvmls 2019 feedback valhalla update
Jvmls 2019 feedback   valhalla updateJvmls 2019 feedback   valhalla update
Jvmls 2019 feedback valhalla update
 
Pruebas unitarias con django
Pruebas unitarias con djangoPruebas unitarias con django
Pruebas unitarias con django
 
New Features of SQL Server 2016
New Features of SQL Server 2016New Features of SQL Server 2016
New Features of SQL Server 2016
 
Time Series Analysis Sample Code
Time Series Analysis Sample CodeTime Series Analysis Sample Code
Time Series Analysis Sample Code
 
COSCUP2023 RSA256 Verilator.pdf
COSCUP2023 RSA256 Verilator.pdfCOSCUP2023 RSA256 Verilator.pdf
COSCUP2023 RSA256 Verilator.pdf
 

Plus de Electronic Arts / DICE

High Dynamic Range color grading and display in Frostbite
High Dynamic Range color grading and display in FrostbiteHigh Dynamic Range color grading and display in Frostbite
High Dynamic Range color grading and display in Frostbite
Electronic Arts / DICE
 

Plus de Electronic Arts / DICE (20)

GDC2019 - SEED - Towards Deep Generative Models in Game Development
GDC2019 - SEED - Towards Deep Generative Models in Game DevelopmentGDC2019 - SEED - Towards Deep Generative Models in Game Development
GDC2019 - SEED - Towards Deep Generative Models in Game Development
 
SIGGRAPH 2010 - Style and Gameplay in the Mirror's Edge
SIGGRAPH 2010 - Style and Gameplay in the Mirror's EdgeSIGGRAPH 2010 - Style and Gameplay in the Mirror's Edge
SIGGRAPH 2010 - Style and Gameplay in the Mirror's Edge
 
SEED - Halcyon Architecture
SEED - Halcyon ArchitectureSEED - Halcyon Architecture
SEED - Halcyon Architecture
 
Syysgraph 2018 - Modern Graphics Abstractions & Real-Time Ray Tracing
Syysgraph 2018 - Modern Graphics Abstractions & Real-Time Ray TracingSyysgraph 2018 - Modern Graphics Abstractions & Real-Time Ray Tracing
Syysgraph 2018 - Modern Graphics Abstractions & Real-Time Ray Tracing
 
Khronos Munich 2018 - Halcyon and Vulkan
Khronos Munich 2018 - Halcyon and VulkanKhronos Munich 2018 - Halcyon and Vulkan
Khronos Munich 2018 - Halcyon and Vulkan
 
CEDEC 2018 - Towards Effortless Photorealism Through Real-Time Raytracing
CEDEC 2018 - Towards Effortless Photorealism Through Real-Time RaytracingCEDEC 2018 - Towards Effortless Photorealism Through Real-Time Raytracing
CEDEC 2018 - Towards Effortless Photorealism Through Real-Time Raytracing
 
CEDEC 2018 - Functional Symbiosis of Art Direction and Proceduralism
CEDEC 2018 - Functional Symbiosis of Art Direction and ProceduralismCEDEC 2018 - Functional Symbiosis of Art Direction and Proceduralism
CEDEC 2018 - Functional Symbiosis of Art Direction and Proceduralism
 
SIGGRAPH 2018 - PICA PICA and NVIDIA Turing
SIGGRAPH 2018 - PICA PICA and NVIDIA TuringSIGGRAPH 2018 - PICA PICA and NVIDIA Turing
SIGGRAPH 2018 - PICA PICA and NVIDIA Turing
 
SIGGRAPH 2018 - Full Rays Ahead! From Raster to Real-Time Raytracing
SIGGRAPH 2018 - Full Rays Ahead! From Raster to Real-Time RaytracingSIGGRAPH 2018 - Full Rays Ahead! From Raster to Real-Time Raytracing
SIGGRAPH 2018 - Full Rays Ahead! From Raster to Real-Time Raytracing
 
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open ProblemsHPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
 
EPC 2018 - SEED - Exploring The Collaboration Between Proceduralism & Deep Le...
EPC 2018 - SEED - Exploring The Collaboration Between Proceduralism & Deep Le...EPC 2018 - SEED - Exploring The Collaboration Between Proceduralism & Deep Le...
EPC 2018 - SEED - Exploring The Collaboration Between Proceduralism & Deep Le...
 
DD18 - SEED - Raytracing in Hybrid Real-Time Rendering
DD18 - SEED - Raytracing in Hybrid Real-Time RenderingDD18 - SEED - Raytracing in Hybrid Real-Time Rendering
DD18 - SEED - Raytracing in Hybrid Real-Time Rendering
 
Creativity of Rules and Patterns: Designing Procedural Systems
Creativity of Rules and Patterns: Designing Procedural SystemsCreativity of Rules and Patterns: Designing Procedural Systems
Creativity of Rules and Patterns: Designing Procedural Systems
 
Shiny Pixels and Beyond: Real-Time Raytracing at SEED
Shiny Pixels and Beyond: Real-Time Raytracing at SEEDShiny Pixels and Beyond: Real-Time Raytracing at SEED
Shiny Pixels and Beyond: Real-Time Raytracing at SEED
 
A Certain Slant of Light - Past, Present and Future Challenges of Global Illu...
A Certain Slant of Light - Past, Present and Future Challenges of Global Illu...A Certain Slant of Light - Past, Present and Future Challenges of Global Illu...
A Certain Slant of Light - Past, Present and Future Challenges of Global Illu...
 
Physically Based Sky, Atmosphere and Cloud Rendering in Frostbite
Physically Based Sky, Atmosphere and Cloud Rendering in FrostbitePhysically Based Sky, Atmosphere and Cloud Rendering in Frostbite
Physically Based Sky, Atmosphere and Cloud Rendering in Frostbite
 
High Dynamic Range color grading and display in Frostbite
High Dynamic Range color grading and display in FrostbiteHigh Dynamic Range color grading and display in Frostbite
High Dynamic Range color grading and display in Frostbite
 
4K Checkerboard in Battlefield 1 and Mass Effect Andromeda
4K Checkerboard in Battlefield 1 and Mass Effect Andromeda4K Checkerboard in Battlefield 1 and Mass Effect Andromeda
4K Checkerboard in Battlefield 1 and Mass Effect Andromeda
 
FrameGraph: Extensible Rendering Architecture in Frostbite
FrameGraph: Extensible Rendering Architecture in FrostbiteFrameGraph: Extensible Rendering Architecture in Frostbite
FrameGraph: Extensible Rendering Architecture in Frostbite
 
Lighting the City of Glass
Lighting the City of GlassLighting the City of Glass
Lighting the City of Glass
 

Introduction to Data Oriented Design

  • 2. So what is this Data-Oriented Design?
  • 3. It’s about on shifting focus to how data is read and written
  • 6. A read from memory takes ~600 cycles at 3.2 GHz
  • 7. A read from memory takes 40 cycles at 300 MHz
  • 8. Performance Disks (Blu-ray/DVD/HDD) Main Memory L2 Cache L1 Cache CPU / Registers Latency :( 600 cycles 40 cycles 1 – 2 cycles
  • 9.
  • 10.
  • 11.
  • 12. Example - OOD class Bot { ... Vec3 m_position; ... float m_mod; ... float m_aimDirection; ... void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } }
  • 13. Example - OOD class Bot { ... Vec3 m_position; ... float m_mod; ... float m_aimDirection; ... void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } } icache-miss
  • 14. Example - OOD class Bot { ... Vec3 m_position; ... float m_mod; ... float m_aimDirection; ... void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } } icache-miss data-miss
  • 15. Example - OOD class Bot { ... Vec3 m_position; ... float m_mod; ... float m_aimDirection; ... void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } } icache-miss data-miss Unused cached data
  • 16. Example - OOD class Bot { ... Vec3 m_position; ... float m_mod; ... float m_aimDirection; ... void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } } icache-miss data-miss Unused cached data Very hard to optimize!
  • 17. Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots)
  • 18. Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600
  • 19. Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600 m_position – 600
  • 20. Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600 m_position – 600 m_mod - 600
  • 21. Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600 m_position – 600 m_mod - 600 ~20 cycles
  • 22. Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 ~20 cycles
  • 23. Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 ~20 cycles iCache – 600 m_position – 600 m_mod - 600 aimDir – 100
  • 24. Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 ~20 cycles iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 iCache – 600 m_position – 600 m_mod - 600 aimDir – 100
  • 25. Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 ~20 cycles iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 iCache – 600 m_position – 600 m_mod - 600 aimDir – 100
  • 26. Example - OOD void updateAim(Vec3 target) { m_aimDirection = dot3(m_position, target) * m_mod; } Lets say we call this code 4 times (4 diffrent Bots) iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 ~20 cycles iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 iCache – 600 m_position – 600 m_mod - 600 aimDir – 100 7680
  • 28.
  • 29.
  • 30. Example - DOD void updateAims(float* aimDir,const AimingData* aim, Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i],target) * aim->mod[i]; } }
  • 31. Example - DOD void updateAims(float* aimDir,const AimingData* aim, Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i],target) * aim->mod[i]; } } What has changed?
  • 32. Example - DOD void updateAims(float* aimDir,const AimingData* aim, Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i],target) * aim->mod[i]; } } Only read needed inputs What has changed?
  • 33. Example - DOD void updateAims(float* aimDir,const AimingData* aim, Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i],target) * aim->mod[i]; } } Only read needed inputs Write to linear array What has changed?
  • 34. Example - DOD void updateAims(float* aimDir,const AimingData* aim, Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i],target) * aim->mod[i]; } } Only read needed inputs Write to linear array Loop over all the data What has changed?
  • 35. Example - DOD void updateAims(float* aimDir,const AimingData* aim, Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i],target) * aim->mod[i]; } } Only read needed inputs Write to linear array Loop over all the data Actual code unchanged What has changed?
  • 36. Example - DOD void updateAims(float* aimDir,const AimingData* aim, Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i],target) * aim->mod[i]; } } Only read needed inputs Write to linear array Loop over all the data Actual code unchanged What has changed? Code separated
  • 37. Example - DOD void updateAims(float* aimDir, const AimingData* aim, Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } }
  • 38. Example - DOD void updateAims(float* aimDir, const AimingData* aim, Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600
  • 39. Example - DOD void updateAims(float* aimDir, const AimingData* aim, Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600 positions – 600
  • 40. Example - DOD void updateAims(float* aimDir, const AimingData* aim, Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600 positions – 600 mod - 600
  • 41. Example - DOD void updateAims(float* aimDir, const AimingData* aim, Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600 positions – 600 mod - 600 ~20 cycles
  • 42. Example - DOD void updateAims(float* aimDir, const AimingData* aim, Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600 positions – 600 mod - 600 aimDir – 100 ~20 cycles
  • 43. Example - DOD void updateAims(float* aimDir, const AimingData* aim, Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600 positions – 600 mod - 600 aimDir – 100 ~20 cycles
  • 44. Example - DOD void updateAims(float* aimDir, const AimingData* aim, Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600 positions – 600 mod - 600 aimDir – 100 ~20 cycles
  • 45. Example - DOD void updateAims(float* aimDir, const AimingData* aim, Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600 positions – 600 mod - 600 aimDir – 100 ~20 cycles
  • 46. Example - DOD void updateAims(float* aimDir, const AimingData* aim, Vec3 target, uint count) { for (uint i = 0; i < count; ++i) { aimDir[i] = dot3(aim->positions[i], target) * aim->mod[i]; } } iCache – 600 positions – 600 mod - 600 aimDir – 100 ~20 cycles 1980
  • 47. Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0
  • 48. Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one 128 byte cache line
  • 49. Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one 128 byte cache line
  • 50. Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one 128 byte cache line
  • 51. Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one 128 byte cache line
  • 52. Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one 128 byte cache line
  • 53. Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one 128 byte cache line
  • 54. Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one 128 byte cache line
  • 55. Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one 128 byte cache line
  • 56. Data layout OOD vs DOD pos0 mod0 aimDir0 pos0 Pos1 mod1 aimDir1 pos0 pos0 pos0 pos1 pos1 pos1 pos1 pos2 pos2 pos2 pos2 pos3 pos3 pos3 pos3 mod0 mod1 mod2 mod3 aimDir0 aimDir1 aimDir2 aimDir3 pos0 pos0 pos0 Each color block is one 128 byte cache line
  • 57. Its all about memory
  • 58.
  • 59.
  • 60.
  • 62.
  • 63.
  • 65. Example: Area Triggers position position position position next position position position position next position position position position next Source data (Linked List)
  • 66. Example: Area Triggers position position position position next position position position position next position position position position next Source data (Linked List) Native Data (Array) position position position position position position position position position position position position position position count
  • 69. Example: Culling System Old System New System (Linear arrays and brute force)
  • 70. Example: Culling System Old System New System (Linear arrays and brute force) 3x faster, 1/5 code size, simpler
  • 71. Data Oriented Design Delivers:
  • 76.
  • 77.