12 Unity DOTS
This chapter covers
- The performance benefits of using SIMD instructions and parallel processing.
- How to use Unity DOTS Burst compiler and Jobs system on top of DOD to add SIMD and multi-threading to our code.
- Where and how ECS fits into our codebase.
- How to parallelize GameObject transform access using TransformAccessArray.
With data-oriented design, we placed our data in flat arrays, which helped us leverage the L1 cache and achieve significant performance gains while reducing code complexity. In this chapter, we will explore how to use Unity DOTS to achieve even greater performance gains by leveraging both SIMD-friendly (Single Instruction, Multiple Data) commands and parallel processing. Our existing data-oriented design architecture makes it trivial to add DOTS to our project, albeit at the cost of additional code complexity.
Both SIMD vectorization and parallel processing improve performance by performing more work simultaneously, but they operate at different levels of the CPU.
- SIMD operates on a single core and performs the same operation on multiple values simultaneously.
- Parallel processing leverages multiple CPU cores by dividing the workload into tasks.
Let’s start by looking at how we can add SIMD operations to our game using the Burst compiler, Unity’s high-performance compiler for DOTS code.