OOP is dead, long live Data-oriented design
Presenter : Bright Sun
Based off of Stoyan Nikolov’s talk at CppCon2018
A bit on Stoyan Nikolov
Software Architect at Coherent Labs
Worked on game development
Last 6.5 years working on
Chromium
Webkit
Hummingbird
A quick review on 411
Pipelining Pipelining Pipelining
Pipelining Pipelining Pipelining
Pipelining Pipelining Pipelining
Pipelining Pipelining Pipelining
Instruction Cache
Data Cache
Branch Predictor
What is wrong with oop?
OOP marries data with operations
...it’s not a happy marriage
Heterogeneous data is brought together by a “logical” black box object
The object is used and reused in different contexts
High level of complexity in states
Simply put, a lot of branches
Impacts on Performance, Scalability, Modifiability, Testability
Data-Oriented design
Data-Oriented design
Separates data from logic
Structs and data live different lives
Objective of logic is to transform data into a usable form
The logic does not abstract away the data
Leads to functions that work on arrays
Reorganize data according to usage
If we are not going to use a piece of data, why pack it together?
Data-Oriented design Cont.
Avoids extra states
No Virtual Calls
Promotes deep Domain Knowledge
What is an Animation?
Contains and cycle over properties over time
Keyframes
Interpolation
What are the challenges?
Different property types
In this case, we also have a DOM Api (Javascript)
Animation is not static, runtime modifiable
The OOP way (Chromium 66)
Chromium has 2 animation systems
We’ll be looking at the Blink system
Employs classic oop
Closely follows HTML5 and IDL
The Flow
Unclear lifetime semantics
The State (Not the one on HBO)
Extra States, Branch Mispredictions
The Keyframe Effect
Updating time and values
Jumping Contexts
Coupling between systems
Interpolating values
Dynamic Type Erasure, data and instruction cache miss
Apply the new value
Guaranteed cache misses
Recap
We used more than 6 non-trivial classes�
Objects contain smart pointers to other objects
Interpolation uses abstract classes to handle different property types
Animations directly reach out to other systems - coupling
Calling events
Setting the value in the DOM Element
How is the lifetime of Elements synchronized?�
�
24
Back to the Drawing Board
Animation Data Operations
Tick (99.9%)
Add
Remove
Pause
Ticks and Lyme Disease
Animation Tick Input
Animation Definitions
Time
Animation Tick Output
Changed property
New property values
Mapping between the two
The Animation Controller
Go FLaT
Avoid type erasure
Ticking Animations
Performance Increases
Scalability
OOP:
Account for dependencies. Are methods thread safe?
Thread balances.
DoD:
Separating active and inactive animations creates more balances threads
Build lists of modified modes( vector push across multiple threads )
Classic fork-join.
Links and Demos