liveBook · Manning

What you will learn in High Performance Unity Game Development

Using data-oriented design

by Nitzan Wilnai · Manning Early Access Program (MEAP)

Chapter by chapter

Chapter 1: Understanding data-oriented design

Introduces data-oriented design as a way to organize Unity game code around data flow, explains its main benefits, and distinguishes it from Unity DOTS and ECS.

1.1 Core advantages of data-oriented design · 1.1.1 Where DOD provides the most value · 1.2 Improving performance by leveraging modern hardware architecture · 1.2.1 Why memory access limits performance · 1.2.2 Why the CPU cache is faster than main memory · 1.2.3 How the CPU retrieves data into the cache · 1.2.4 How cache lines move data into the CPU cache · 1.2.5 Using data locality to reduce cache misses · 1.3 Reducing code complexity by separating data and logic · 1.4 Improving extensibility by solving for data · 1.5 Unity DOTS, ECS, and how they relate to DOD · 1.6 Summary

What you learn in chapter 1 →

Chapter 2: Structuring data for performance

The chapter introduction connects array-based data locality to performance and previews a closer look at how data is stored.

2.1 Struct vs. class - how data affects performance · 2.2 Stack vs heap - how memory affects performance · 2.2.1 The stack · 2.2.2 The heap · 2.3 Passing by value vs. by reference - performance and common issues · 2.3.1 Copying by value and common issues · 2.3.2 Copying by value and performance · 2.4 The intricacies of struct allocations in C# · 2.4.1 Structs as member variables · 2.4.2 Structs with arrays · 2.4.3 Structs with Strings · 2.5 Data locality and contiguous memory - arrays of structs vs arrays of classes · 2.6 Data types and Performance · 2.6.1 Performance · 2.6.2 Memory · 2.7 Conclusion · 2.8 Summary

What you learn in chapter 2 →

Chapter 3: Memory allocations and performance

The introduction explains why memory management matters to game performance and identifies garbage collection and fragmentation as risks explored later in the chapter.

3.1 Memory fragmentation · 3.2 Avoiding garbage collector related slowdowns · 3.2.1 GC Issue #1 — memory isn’t freed immediately · 3.2.2 GC issue #2 — performance · 3.2.3 GC issue #3 — memory fragmentation · 3.2.4 GC best practices · 3.3 Avoiding fragmented memory and garbage collection with object pools · 3.3.1 Common causes of memory fragmentation · 3.3.2 Using object pools to avoid memory fragmentation and garbage collection · 3.3.3 What to do when object pools run out of room · 3.3.4 Object pools in data-oriented design · 3.3.5 Common bugs caused by object pools · 3.4 Ideal memory allocations · 3.5 Conclusion · 3.6 Summary

What you learn in chapter 3 →

Chapter 4: Data and logic

Introduces the survivor game used to illustrate a data-oriented architecture, distinguishing balance, runtime game data, and logic while outlining the example’s gameplay and pooling constraint.

4.1 Simple DOD Architecture · 4.2 The Balance · 4.3 The GameData · 4.4 The Logic · 4.4.1 Logic accessibility · 4.4.2 AllocateGameData() - Allocating all the data for our game · 4.4.3 StartGame() - Initializing our gameplay data · 4.4.4 Tick() - Handling frame-by-frame gameplay · 4.4.5 Handling user input · 4.4.6 getEnemySpawnPosition() - Placing an enemy within range of the player · 4.4.7 Functions called by Tick() · 4.5 Conclusion · 4.6 Summary

What you learn in chapter 4 →

Chapter 5: Game board and game loop

The introduction positions Board and Game as the remaining parts of the DOD architecture and explains why Unity is the setting for implementing them.

5.1 DOD architecture, continued · 5.1.1 Game · 5.1.2 Board · 5.1.3 Scene hierarchy · 5.1.4 Unity scenes and code complexity · 5.2 The Board implementation · 5.2.1 Init() · 5.2.2 Show() · 5.2.3 5.2.3 Hide() · 5.2.4 Tick() · 5.2.5 handleInput() · 5.3 The Game loop implementation · 5.3.1 Start() · 5.3.2 StartGame() · 5.3.3 Update() · 5.3.4 GameOver() · 5.4 Conclusion · 5.5 Summary

What you learn in chapter 5 →

Chapter 6: Common data structures: List, Stack, and Queue

The introduction explains why arrays fit data-oriented design and why built-in collections, despite making dynamic changes easier, warrant scrutiny.

6.1 C# List · 6.1.1 C# List vs Linked List · 6.1.2 List and dynamic resizing · 6.1.3 List and built-in functions · 6.1.4 List and performance · 6.1.5 Replacing List with an array · 6.2 DOD List Implementation · 6.2.1 DOD Implementation of List.Add() · 6.2.2 DOD implementation of List Remove() · 6.2.3 DOD List helper functions, or lack of · 6.2.4 Array.Copy() · 6.2.5 Using the AliveEnemyIndices array · 6.3 DOD stack implementation · 6.4 Queue · 6.5 Putting it all together · 6.5.1 Adding the alive and dead indices arrays to GameData · 6.5.2 Allocating the alive and dead indices arrays · 6.5.3 Initializing the alive and dead indices arrays · 6.5.4 Spawning and positioning enemies · 6.6 Visualizing enemy changes on the board · 6.6.1 Allocating temporary arrays in the Board · 6.6.2 Populating the addedEnemyIndices array · 6.6.3 Populating the removedEnemyIndices array · 6.7 Conclusion · 6.8 Summary

What you learn in chapter 6 →

Chapter 7: Separating data and logic

The introduction presents separating data from logic and keeping code deliberately simple as ways to reduce complexity and make future features easier to add.

7.1 Save/Load · 7.1.1 Storing the save data · 7.1.2 The GameDataIO static class · 7.1.3 Saving to a local file · 7.1.4 Loading from a local file · 7.1.5 Backwards compatibility · 7.1.6 Handling GameData changes caused by Balance · 7.1.7 Debugging · 7.1.8 Separating loading by source · 7.1.9 Continuing gameplay · 7.2 Asset loading · 7.2.1 The asset manager · 7.2.2 Using the asset manager · 7.2.3 Multiple asset sources · 7.2.4 Other examples · 7.3 Conclusion · 7.4 Summary

What you learn in chapter 7 →

Chapter 8: Separating asset data and logic

This introduction explains why menu development benefits from separating dynamic UI asset data from static components and treating each menu’s needs independently.

8.1 Separating menu data from logic · 8.2 The main menu implementation · 8.2.1 Understanding the asset data problem · 8.2.2 Separating asset data from logic · 8.2.3 Introducing the meta data · 8.2.4 The main menu implementation · 8.3 The game over menu implementation · 8.3.1 Init() · 8.3.2 Show() · 8.3.3 Hide() · 8.3.4 goToMainMenu() · 8.4 The pause menu implementation · 8.5 The in-game menu implementation · 8.6 Connecting the menus in the game loop · 8.6.1 Referencing the menus · 8.7 Building complex menus · 8.8 Conclusion · 8.9 Summary

What you learn in chapter 8 →

Chapter 9: Tooltime data parsing

The introduction explains why separating balance data from Unity scene and runtime assets can improve designers’ workflow, reduce runtime checks, and support live updates and testing.

9.1 Moving balance data to an external asset · 9.2 Parsing the balance · 9.3 Loading the balance · 9.4 Validating balance data at tool time · 9.5 Handling live balance updates · 9.6 A/B Testing · 9.7 Conclusion · 9.8 Summary

What you learn in chapter 9 →

Chapter 10: DOD and Dictionaries

The introduction contrasts dictionary lookups with indexed arrays and explains why data-oriented design favors arrays for enemy balance data despite dictionaries’ O(1) complexity.

10.1 Dictionary performance · 10.2 Supporting multiple enemies in the balance · 10.2.1 Storing the new enemy data · 10.2.2 Parsing the balance data · 10.2.3 Loading the balance data · 10.2.4 Referencing different enemies · 10.3 Runtime data · 10.4 The gameplay logic · 10.5 The board · 10.5.1 Setting the pool size · 10.5.2 Showing newly added enemies · 10.5.3 Hiding removed enemies · 10.5.4 Moving alive enemies · 10.6 Backwards compatibility · 10.6.1 The Implementation · 10.6.2 Handling edge cases · 10.7 Conclusion · 10.8 Summary

What you learn in chapter 10 →

Chapter 11: Branching, performance, and extendibility

The introduction explains how branches affect code complexity and runtime performance, and how grouping data can remove checks from hot loops.

11.1 Branch prediction · 11.2 Avoiding early return · 11.3 Unity and null checks · 11.3.1 Check once · 11.3.2 Zero Tolerance · 11.3.3 Own the lifetime · 11.3.4 Avoid fire-and-forget behavior · 11.4 Separating data to reduce branch checks · 11.5 Separating objects to avoid branch checks · 11.6 Default parameter values can hide branches · 11.7 Conclusion · 11.8 Summary

What you learn in chapter 11 →

Chapter 12: Unity DOTS

The chapter introduction connects the existing data-oriented design to DOTS and distinguishes how SIMD and parallel processing increase throughput.

12.1 Adding SIMD vectorization using the Burst compiler · 12.1.1 GameData · 12.1.2 Allocating data · 12.1.3 Moving enemies · 12.2 Parallelizing work with Jobs · 12.3 ECS and code complexity · 12.4 Parallelizing GameObject transform access with TransformAccessArray · 12.5 Conclusion · 12.6 Summary

What you learn in chapter 12 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.