appendix-a

Appendix A. Data-Oriented Design in action

 

In Chapter 1, we learned how data locality can improve the performance of our code. We learned that grouping data that is used together can improve performance by limiting cache misses and that placing our data in arrays is an easy and efficient way to group data. But how much performance improvement can we expect? This appendix is designed to show a real-world example of how much performance we can expect by using data locality.

A.1 OOP without data locality

Let's implement a simple test of moving enemies around to test how much of a performance boost we get from data locality. For our first test, we will allocate a bunch of Enemy objects, move them around, and time how long it takes.

Listing A.1 shows what a typical OOP Enemy class could look like:

A.2 with data locality

A.3 Optimized OOP

A.3.1 Optimization caveat

A.4 DOD and arrays

A.5 Conclusion