UNITY, WE HAVE A PROBLEM
I love optimization but you reach a point where you only get a fraction out of it. It’s best to stop there.
This point was reached with 150k items. After that 60fps couldn’t be maintained.
I was pretty much in disbelief. How can something so simple reach it’s limits at such a low number.
It was time to reassess my assumptions. Is this what I’m doing even possible on the most basic level?
I wrote a C# console application to test things out. Something really simple. 1 million vector additions. No, not even real vectors. Just adding 2 float coordinates. These are the results:
The first one took longer because of the JIT compilation. The rest is below 10ms. Cool, that means it’s definitely possible.
Then I wrote the same program in Unity.
Wait what? 85ms? Factor 10? Are you kidding me? First I thought the problem occurs from wrong measuring but you can pretty much feel the 10 times difference when initiating a new loop with pressing a new key.
So, all optimizations are pretty much in vain unless I find out what’s the big problem here.
Here you can find the TestProjects:
I seriously hope someone has insights what’s going on. Maybe I’m doing something wrong but it’s so reduced, I can’t see it.
Update: In this test the main culprit is the GC. Unity is already infamous to have an old/bad GC. The test just shows how big the difference really is.
Read more: Factorio in Unity/C# – Part 3 Goal reached