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.
After this chapter you will be able to
- Data-oriented game code. Explain how data-oriented design structures game code around the data systems need and transform, rather than relationships between objects. Describe the examples given: related runtime data in arrays, data separated from logic, and systems processing many items at once.
- Reasons for a data-first approach. Explain why data access can limit gameplay performance even when CPUs calculate quickly, and state the three advantages the section attributes to organizing data around its processing: efficient CPU access, explicit data and dependencies, and easier extension through data transformations.
- Data locality and performance. Explain why storing data that a gameplay system processes together close together in memory can improve performance, and contrast this with object-oriented layouts that may retrieve unrelated data.
- Explicit data and execution paths. Explain how explicit data-oriented code makes gameplay systems easier to understand and how removing work from execution paths can also improve performance.
- Feature extension through data flow. Describe how separating data from logic changes the questions developers ask when adding a feature and why that can make extension more predictable.
- High-value DOD candidates. Explain which gameplay systems are strong candidates for DOD and why a data-first approach can help long-running games evolve.
- Practical hybrid Unity approach. Explain the tradeoffs of adopting DOD and describe the hybrid approach the section recommends for Unity projects.
- Data-oriented performance foundation. Explain how organizing runtime data around its processing can improve performance when a gameplay system handles large amounts of similar data. Describe why that organization also makes further optimization easier if it becomes necessary.
- Premature optimization distinction. Distinguish adopting DOD as an architectural foundation from spending time on an unneeded optimization. Explain why the section still calls for profiling on target hardware.
- Memory access performance limit. Explain why retrieving enemy data can take longer than the movement calculation and how a cached copy reduces the wait.
- DOD data organization purpose. Explain why DOD aims to bring in as much data needed by the logic as possible when the CPU retrieves data from memory.
- Cache hierarchy and access speed. Explain why the CPU cache, especially L1, is faster to access than main memory, using the section’s approximate retrieval times.
- Cache lookup and misses. Describe where the CPU looks for needed data and distinguish a cache hit from a cache miss.
- Nearby data and locality. Explain how retrieving nearby data into the cache motivates placing data processed together close together in memory.
- Cache lines and nearby data. Explain that when requested data is not cached, the CPU retrieves a block containing it, called a cache line, which also contains nearby data. Describe why placing values processed together close in memory can make one retrieval provide more of the needed data.
- Cache-line transfers and lookup. Explain that data moves from lower levels of the memory hierarchy toward the CPU in cache-line-sized blocks, and that the CPU looks for a variable in L1 before checking lower cache levels and main memory.
- Related enemy data locality. Explain how placing an enemy’s position, direction, and velocity together can let a request for position bring in the other values needed by Move(), reducing separate trips to main memory.
- Aligned cache-line boundaries. Explain why reversing the order of the three enemy variables does not change this example’s result: all three still fall within one fixed, address-aligned cache line.
- Data locality and object limits. Explain why grouping data used together can help the CPU cache, and why one large Enemy object becomes difficult to lay out efficiently for different functions.
- Structure of Arrays layout. Describe how the section reorganizes enemy runtime data into a Structure of Arrays and how functions use that data.
- Array cache-line benefits. Trace why processing all enemies from field arrays can reduce cache misses, while acknowledging the initial memory retrievals.
- Gameplay as data transformation. Explain how the section models gameplay logic as functions that take relevant data, transform it, and produce output data rather than owning behavior in an object.
- Behavior composition and data layout. Distinguish the section’s data-oriented approach from both inheritance and assembling enemies from behavior components, explaining why composition alone does not resolve its data-organization concern.
- Zombie Duck data transformation. Trace how the Zombie Duck’s core behavior is defined by data and logic rather than by a new enemy type: check its distance from the player, then set its velocity to a designer-set value or zero according to the result.
- Predictable feature development effort. Distinguish the hoped-for reduction in later feature work from the section’s account of how accumulated object relationships can raise that work, and explain why a data-oriented approach can keep architectural effort more predictable.
- DOD and DOTS relationship. Distinguish DOD from Unity DOTS and ECS. Explain that DOD principles do not require Unity's tools, though those tools can build on a DOD foundation.
- Data locality and ECS tradeoffs. Explain why the ECS pattern alone does not ensure data locality, and justify when its additional structure might be worthwhile instead of direct arrays and functions.
Section by section
Introduction
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.
- Data-oriented game code: Explain how data-oriented design structures game code around the data systems need and transform, rather than relationships between objects. Describe the examples given: related runtime data in arrays, data separated from logic, and systems processing many items at once.
Why it matters: This is the organizing idea behind the game architecture developed later in the book. - Reasons for a data-first approach: Explain why data access can limit gameplay performance even when CPUs calculate quickly, and state the three advantages the section attributes to organizing data around its processing: efficient CPU access, explicit data and dependencies, and easier extension through data transformations.
Why it matters: The section presents DOD as a response to both performance pressure and the need to change game systems efficiently. - DOD beyond Unity tools: Distinguish data-oriented design from Unity DOTS and ECS by stating that the DOD techniques discussed here can be used with or without those tools.
Why it matters: This distinction lets a Unity developer apply the approach without assuming a particular toolset is required.
Key terms: Data-Oriented Design, DOD, flow and transformation of data, data-first approach, memory, dependencies, extensibility, DOTS, ECS
1.1 Core advantages of data-oriented design
This section explains how data-oriented design can improve gameplay performance, reduce code complexity, and make features easier to extend.
- Data locality and performance: Explain why storing data that a gameplay system processes together close together in memory can improve performance, and contrast this with object-oriented layouts that may retrieve unrelated data.
Why it matters: It connects the way gameplay data is arranged to the work the hardware must do. - Explicit data and execution paths: Explain how explicit data-oriented code makes gameplay systems easier to understand and how removing work from execution paths can also improve performance.
Why it matters: Visible data flow makes a system easier to change while helping developers spot work the CPU need not perform. - Feature extension through data flow: Describe how separating data from logic changes the questions developers ask when adding a feature and why that can make extension more predictable.
Why it matters: A feature can be planned around its data and transformations instead of an expanding web of object relationships.
Key terms: DOD, data, CPU, object-oriented layouts, code complexity, execution paths, transformations, separating data from logic, extensibility, data flow
1.1.1 Where DOD provides the most value
This section identifies where data-oriented design (DOD) is useful in Unity, where it will not help, and why a hybrid approach is often appropriate.
- High-value DOD candidates: Explain which gameplay systems are strong candidates for DOD and why a data-first approach can help long-running games evolve.
Why it matters: It helps you choose systems where changing the data organization is likely to pay off. - Limits of DOD benefits: Distinguish systems that may gain little from DOD from performance bottlenecks that reorganizing gameplay data cannot fix.
Why it matters: It keeps a team from applying DOD where it offers little benefit or cannot address the actual bottleneck. - Practical hybrid Unity approach: Explain the tradeoffs of adopting DOD and describe the hybrid approach the section recommends for Unity projects.
Why it matters: It gives you a practical way to use DOD without forcing an unsuitable structure onto the whole project.
Key terms: DOD, data-first architecture, gameplay systems, arrays, batches, bottleneck, GameObjects, MonoBehaviours, hybrid approach, indices
1.2 Improving performance by leveraging modern hardware architecture
This section argues that data-oriented design provides a performance-conscious foundation rather than premature optimization, while emphasizing the need to profile on target hardware.
- Data-oriented performance foundation: Explain how organizing runtime data around its processing can improve performance when a gameplay system handles large amounts of similar data. Describe why that organization also makes further optimization easier if it becomes necessary.
Why it matters: The section connects a data-layout choice to both immediate performance and the ability to optimize later without starting over. - Premature optimization distinction: Distinguish adopting DOD as an architectural foundation from spending time on an unneeded optimization. Explain why the section still calls for profiling on target hardware.
Why it matters: It explains why choosing a performant architecture early does not mean guessing which additional optimizations a game needs.
Key terms: Data-Oriented Design, data locality, cache line, batching, vectorization, parallel execution, premature optimization, profile, target hardware, bottlenecks
1.2.1 Why memory access limits performance
This section uses enemy movement to show why waiting for data can limit performance and why DOD organizes data to make better use of the CPU cache.
- Enemy movement data and calculation: Describe the data and calculation needed to move an enemy: multiply its direction by its velocity, then add the result to its position.
Why it matters: The simple movement example makes the cost of getting data easier to see. - Memory access performance limit: Explain why retrieving enemy data can take longer than the movement calculation and how a cached copy reduces the wait.
Why it matters: It explains why speeding up calculations alone may not speed up gameplay. - DOD data organization purpose: Explain why DOD aims to bring in as much data needed by the logic as possible when the CPU retrieves data from memory.
Why it matters: It connects the memory-access problem to the reason DOD pays attention to data layout.
Key terms: position, direction, velocity, Move(), main memory, CPU cache, register, access latency, DOD, logic
1.2.2 Why the CPU cache is faster than main memory
This section explains why accessing data in the CPU cache is faster than retrieving it from main memory and how data-oriented design can improve the chances of finding needed data in the cache.
- Cache hierarchy and access speed: Explain why the CPU cache, especially L1, is faster to access than main memory, using the section’s approximate retrieval times.
Why it matters: The time spent retrieving game data can differ greatly depending on where that data is found. - Cache lookup and misses: Describe where the CPU looks for needed data and distinguish a cache hit from a cache miss.
Why it matters: Cache hits and misses name the difference between finding needed data close to the CPU and having to fetch it elsewhere. - Nearby data and locality: Explain how retrieving nearby data into the cache motivates placing data processed together close together in memory.
Why it matters: Keeping related game data together can make later accesses faster by increasing cache hits.
Key terms: CPU cache, L1 cache, main memory, cache hit, cache miss, cache levels, Data-Oriented Design, L1 cache hits, cache misses
1.2.3 How the CPU retrieves data into the cache
The section explains how a cache line brings nearby data into the CPU cache and why placing related values close together can make a memory retrieval more useful.
- Cache lines and nearby data: Explain that when requested data is not cached, the CPU retrieves a block containing it, called a cache line, which also contains nearby data. Describe why placing values processed together close in memory can make one retrieval provide more of the needed data.
Why it matters: It explains why the memory layout of related values can affect how much useful data the CPU gets from one retrieval.
Key terms: cache line, main memory
1.2.4 How cache lines move data into the CPU cache
This section explains how cache lines bring blocks of memory toward the CPU and why keeping an enemy’s related movement data in one aligned cache line can reduce memory trips.
- Cache-line transfers and lookup: Explain that data moves from lower levels of the memory hierarchy toward the CPU in cache-line-sized blocks, and that the CPU looks for a variable in L1 before checking lower cache levels and main memory.
Why it matters: Cache-line transfers explain why the memory surrounding a requested variable can affect performance. - Related enemy data locality: Explain how placing an enemy’s position, direction, and velocity together can let a request for position bring in the other values needed by Move(), reducing separate trips to main memory.
Why it matters: Grouping values used together can spare the CPU additional waits for memory. - Aligned cache-line boundaries: Explain why reversing the order of the three enemy variables does not change this example’s result: all three still fall within one fixed, address-aligned cache line.
Why it matters: The relevant question is whether needed values share a cache line, not whether they appear in the order the code reads them.
Key terms: cache line, L1 cache, L2 cache, L3 cache, main memory, data locality, m_position, m_direction, m_velocity, address alignment
1.2.5 Using data locality to reduce cache misses
This section explains how grouping enemy data in arrays improves data locality and helps reduce CPU cache misses.
- Data locality and object limits: Explain why grouping data used together can help the CPU cache, and why one large Enemy object becomes difficult to lay out efficiently for different functions.
Why it matters: It explains why keeping all enemy fields together does not reliably give each function cache-friendly input. - Structure of Arrays layout: Describe how the section reorganizes enemy runtime data into a Structure of Arrays and how functions use that data.
Why it matters: This layout lets each operation receive the needed fields while keeping elements of each field together in memory. - Array cache-line benefits: Trace why processing all enemies from field arrays can reduce cache misses, while acknowledging the initial memory retrievals.
Why it matters: It connects the array layout to the cache behavior that motivates the change.
Key terms: data locality, cache line, cache-line address alignment, Enemy object, Structure of Arrays, SoA, contiguous memory, MoveAllEnemies(), cache miss, position[0]
1.3 Reducing code complexity by separating data and logic
The section shows how separating runtime data from logic lets gameplay systems transform the data they need without organizing every enemy behavior around objects or components.
- Gameplay as data transformation: Explain how the section models gameplay logic as functions that take relevant data, transform it, and produce output data rather than owning behavior in an object.
Why it matters: Thinking in terms of inputs and outputs makes gameplay systems easier to reason about. - Enemy behavior data flows: Trace how the section expresses enemy movement, player tracking, teleporting on hit, or visual positioning as inputs, transformations, and outputs.
Why it matters: The enemy examples make the input-and-output approach concrete, including for Unity visuals. - Behavior composition and data layout: Distinguish the section’s data-oriented approach from both inheritance and assembling enemies from behavior components, explaining why composition alone does not resolve its data-organization concern.
Why it matters: Changing an inheritance tree into components does not, by itself, organize data for the systems that use it. - Flexible gameplay file organization: Explain why the section does not prescribe a file size or file count for DOD code, and how separating data from logic can affect where related gameplay logic is kept.
Why it matters: DOD is a way to organize work around data, not a rule requiring a particular source-file layout.
Key terms: Data-Oriented Design, runtime data, static functions, input data, transformation, output data, position, direction, velocity, Teleporting Robot
1.4 Improving extensibility by solving for data
The section uses a new enemy feature to show how defining behavior through data and transformations can make extensibility more predictable than fitting changing behaviors into object relationships.
- Zombie Duck data transformation: Trace how the Zombie Duck’s core behavior is defined by data and logic rather than by a new enemy type: check its distance from the player, then set its velocity to a designer-set value or zero according to the result.
Why it matters: The example makes “solve for data” concrete without requiring a new class for every behavior combination. - Behavior combination costs: Explain why new combinations of gameplay behavior can become difficult to add through inheritance or composition, while recognizing when reusable object-oriented abstractions can help.
Why it matters: It explains why reuse alone does not guarantee that changing game features will remain easy to implement. - Predictable feature development effort: Distinguish the hoped-for reduction in later feature work from the section’s account of how accumulated object relationships can raise that work, and explain why a data-oriented approach can keep architectural effort more predictable.
Why it matters: It frames extensibility as the effort of adding comparable features as a game grows, not as a promise that features become effortless.
Key terms: Zombie Duck, velocity, static enemy, data, logic, inheritance, composition, components, overlapping data, reusable architecture
1.5 Unity DOTS, ECS, and how they relate to DOD
This section distinguishes data-oriented design from Unity DOTS and ECS, explains the basic ECS roles, and shows why data layout and practical tradeoffs matter more than adopting a particular tool.
- DOD and DOTS relationship: Distinguish DOD from Unity DOTS and ECS. Explain that DOD principles do not require Unity's tools, though those tools can build on a DOD foundation.
Why it matters: You can apply DOD without committing a project to ECS. - Unity DOTS tool purposes: Describe the broad purpose of Burst, Jobs, ECS, and TransformAccessArray as presented here, without explaining their later implementations.
Why it matters: The tools address different needs, so their names are not interchangeable. - ECS enemy movement roles: Explain what Entity, Component, and System mean in the section's enemy-movement example.
Why it matters: The enemy example gives concrete meaning to ECS terminology before considering its tradeoffs. - Data locality and ECS tradeoffs: Explain why the ECS pattern alone does not ensure data locality, and justify when its additional structure might be worthwhile instead of direct arrays and functions.
Why it matters: It helps you seek the needed data layout before paying for architectural complexity.
Key terms: Data-Oriented Design, DOD, Unity DOTS, ECS, Burst, SIMD, Jobs, TransformAccessArray, Entity, Component
1.6 Summary
Summarizes how data-oriented design improves performance, reduces code complexity, supports extensibility, and relates to ECS and Unity DOTS.
Where this is used later
- Simple DOD Architecture (chapter 4) · Applies data-oriented organization to a game architecture.
- Data locality and contiguous memory - arrays of structs vs arrays of classes (chapter 2) · Applies proximity in memory when comparing arrays of structs and arrays of classes.
- Struct vs. class - how data affects performance (chapter 2) · Introduces why the data on a cache line matters.
- Data types and Performance (chapter 2) · The idea that cache lines carry data into the CPU cache.
- The GameData (chapter 4) · Provides context for organizing game data separately from logic.
- The Logic (chapter 4) · The gameplay logic is developed as operations on game data.
- (chapter intro) (chapter 4) · The earlier discussion of separating data and logic.
- Functions called by Tick() (chapter 4) · Gameplay functions apply transformations to the data used by enemy behaviors.
Concepts explained in this chapter
- data-oriented programmingAn approach to structuring software around the flow and transformation of data rather than relationships between objects.
- data localityThe degree to which related data is stored or accessed close together in the memory hierarchy.
- data flowThe directed movement and transformation of data through the stages of a software system.
- extensibilityThe property of software that allows new capabilities or content to be added with limited changes to existing code.
- cache lineA cache line is a contiguous chunk of memory data transferred into a processor cache as a unit.
- Unity DOTSUnity's Data-Oriented Technology Stack, a collection of packages for building data-oriented applications and games.
- entity component systemECS is an architecture that represents entities separately from their data components and the systems that process those components.
- cache missA memory access in which the requested data is not found in a processor cache and must be retrieved from another memory level.
- CPU cacheA small, fast memory near a processor core that stores data for quicker access than main memory.
- componentAn ECS data unit that stores an attribute or group of attributes associated with an entity.
- entityIn this section's ECS representation, an entity is an index in data arrays that identifies an individual record.
- systemIn this section's ECS representation, a system is logic that operates on data arrays.
- complexity metricA measure of the structural intricacy and difficulty of understanding, modifying, or executing software code.
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.
