15.4HowtoApplyData‐OrientedDesign 255
2. Easier to understand. Having less code means not just higher performance
but also less code to maintain, understand, and keep straight in our heads. Al-
so, each function in itself is much simpler to understand. We’re never in the
situation of having to chase function call after function call to understand all
the consequences of one function. Everything you want to know about it is
there, without any lower-level systems involved.
To be fair and present all the sides, there are two disadvantages to data-
oriented design:
1. It’s different. So far, data-oriented design isn’t taught in Computer Science
curricula, and most developers aren’t actively using it, so it is foreign to most
team members. It also makes it more difficult to integrate with third-party li-
braries and APIs that are not data-oriented.
2. Harder to see the big picture. Because of the emphasis on data and on small
functions that transform data, it might be harder to see and express the big
picture of the program: When is an operation happening? Why is this data
being transformed? This is something that might be addressed with tools,
language extensions, or even a new programming language in the future. For
now, we’ll have to rely on examining the code and the data carefully.
15.4HowtoApplyData‐OrientedDesign
Let’s get more specific and start applying data-oriented design. Eventually, we’d
like the entire game to be architected this way, but we need to start somewhere.
So pick a subsystem that needs to be optimized: animation, artificial intelligence,
physics, etc.
Next, think about all the data involved in that system. Don’t worry too much
about how it is laid out in memory, just about what’s involved. Apart from the
explicit inputs and outputs, don’t forget about data that the system accesses ex-
plicitly, such as a world navigation graph, or global handle managers.
Once you have identified all the data the system needs, carefully think about
how each type of data is used and sort them into read-only, read-write, or write-
only. Those will become your explicit inputs and outputs. It will also allow you
to make better decisions about how to lay out the data.
Also, at this point, it’s important to think about the amount of data. Does this
system ever process more than one of each type of data? If so, start thinking of it
in terms of arrays of data, preferably as contiguous blocks of the same data type
that can be processed at once.