Unity DOTS / ECS Performance: Amazing

10,000 objects gravity simulation running on the laptop

Anton Antich
Superstring Theory
2 min readNov 17, 2023

--

We are using Unity actively in our non-gaming projects, such as a 3D platform for artists ANASAEA.com and spatial collaboration solution BeyondReal.life, so when Unity graduated its Entity-Component-System package into production, we decided to check what the fuss is about and is it really worth it.

The verdict for lazy: it absolutely freaking does. CPU performance improvements go up by 5–50x, depending on how well you can parallelize your simulation.

Now, the actual case in point — being a physicist in the background, I decided to simulate the (in)famous “Three-Body Problem”, only with 10,000 (ten thousand) bodies. It means *in every simulation cycle* we have to calculate the force for each object from *all other* objects — so basically 100,000,000 times (I purposefully did not introduce any optimizations to the algorithm).

Here are the results.

Without Burst Compiler everything just dies, you can’t get it to work. So, if you were wondering if you can simulate the “Big Bang” in pure C# the answer is a definitive “no” :)

With Burst Compiler, which compiles .Net CIL code to SIMD processor instructions, things get a tiny bit better — it runs, but at a pathetic 1–2 fps and the CPU is doing nothing:

Burst Compile + No Parallelization

The real power is unleashed as soon as you schedule your simulation jobs in parallel — we get a decent 16–20 fps on a laptop, and as you can see all CPU cores work like crazy, to its’ fullest potential.

Burst Compile + Parallel Execution

Now, the whole premise behind Unity DOTS (data-oriented technology stack or something) fits very well into functional programming paradigm, which I love. I gotta say, the actual Unity implementation seems unnecessarily over-engineered and too complicated, but in case your product or game is simulation-heavy — it’s so much worth it even now.

If you want to try the simulation described here — the unity project is on github: https://github.com/superstringsoftware/Simulations/

Subscribe and stay tuned for more insights from the world of 3D, VR, and AI developments!

--

--

Anton Antich
Superstring Theory

How to scale startups and do AI and functional programming. Building Integrail.ai: pragmatic AGI platform. Built Veeam from 0 to 1B in revenue in under 10 years