1 of 26

OOP is dead, long live Data-oriented design

Presenter : Bright Sun

Based off of Stoyan Nikolov’s talk at CppCon2018

2 of 26

A bit on Stoyan Nikolov

Software Architect at Coherent Labs

Worked on game development

Last 6.5 years working on

Chromium

Webkit

Hummingbird

3 of 26

A quick review on 411

Pipelining Pipelining Pipelining

Pipelining Pipelining Pipelining

Pipelining Pipelining Pipelining

Pipelining Pipelining Pipelining

Instruction Cache

Data Cache

Branch Predictor

4 of 26

What is wrong with oop?

5 of 26

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

6 of 26

Data-Oriented design

7 of 26

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?

8 of 26

Data-Oriented design Cont.

Avoids extra states

No Virtual Calls

Promotes deep Domain Knowledge

9 of 26

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

10 of 26

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

11 of 26

The Flow

Unclear lifetime semantics

12 of 26

The State (Not the one on HBO)

Extra States, Branch Mispredictions

13 of 26

The Keyframe Effect

14 of 26

Updating time and values

Jumping Contexts

Coupling between systems

15 of 26

Interpolating values

Dynamic Type Erasure, data and instruction cache miss

16 of 26

Apply the new value

Guaranteed cache misses

17 of 26

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

18 of 26

Back to the Drawing Board

Animation Data Operations

Tick (99.9%)

Add

Remove

Pause

19 of 26

Ticks and Lyme Disease

Animation Tick Input

Animation Definitions

Time

Animation Tick Output

Changed property

New property values

Mapping between the two

20 of 26

The Animation Controller

21 of 26

Go FLaT

22 of 26

Avoid type erasure

23 of 26

Ticking Animations

24 of 26

Performance Increases

25 of 26

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.

26 of 26

Links and Demos