For over a decade, Unity developers architected games around GameObject and MonoBehaviour hierarchies. While intuitive and flexible, this object-oriented pattern fragments computer memory. Unity’s Data-Oriented Technology Stack (DOTS)—comprising the C# Job System, the Burst Compiler, and the Entity Component System (ECS)—re-engineers performance from the hardware level up.
1. Why MonoBehaviours Kill CPU Cache Performance
When a CPU executes an instruction, it takes hundreds of cycles to fetch data from main RAM, but only 1-4 cycles from the L1/L2 CPU cache. In traditional Unity, each GameObject is a reference type scattered across arbitrary heap locations. When an engine loop updates 5,000 enemy bullets, the CPU incurs a cache miss for almost every single bullet.
// Traditional OOP Cache Miss Catastrophe:
[RAM Memory Address 0x004A] -> Bullet #1 { Position, Velocity, AudioSource, Collider }
[RAM Memory Address 0x8FA2] -> Bullet #2 (Located gigabytes away in heap!)
Result: CPU L1/L2 cache is constantly flushed and stalled.
// Unity ECS DOTS Linear Chunk Memory:
[Chunk Memory: Contiguous 16KB Array]
Positions: [P1, P2, P3, P4, P5 ... P1000]
Velocities:[V1, V2, V3, V4, V5 ... V1000]
Result: CPU pre-fetches entire arrays into cache; SIMD vectorizes 8 entities per clock cycle!
2. Writing an IJobEntity System with Burst
// Unity DOTS Burst-Compiled Job System:
[BurstCompile]
public partial struct MoveEnemiesJob : IJobEntity {
public float DeltaTime;
public void Execute(ref LocalTransform transform, in Velocity velocity) {
transform.Position += velocity.Value * DeltaTime;
}
}
This single Burst-compiled job can update 100,000 simultaneous units at over 120 FPS on a standard consumer CPU.