My hope for this thread would be to share knowledge and help others.
I’ll start by sharing sharing at least my part of the experience with the dots and c# jobs system. Also I wanted to do some contribution to this awesome society. Also to give others the change to help new comers to create better performing and energy efficient games.
Test scene and setup
I have performance testing environment made with Unitys perfomance testing api. It load scenes with different amount of spawners and and targeting systems. Please note that targeting system is a managed component. If this where a pure ecs based system, then the results would be quite different, but that would destroy the idea of the plugin.
The scene looks like this when its running (256 systems and spawners).
The initial results for the benchmarks before optimization.
What is being measured is targeting systems runners update loop, which runs all the systems.
Measure.Method(() => { runner.Update(); }).WarmupCount(1).MeasurementCount(15).Run();
After the thread scheduling optimizations the results are better.
Big part of the performance improvement comes from better thread scheduling. First I’ll show images of the profiler that visualizes the difference.
Before (old image):
After (256 systems and 2 entity queries):
As you can see the green lines/thread are more dense on the lower image, which means that the cores are using more time on working and less time idling. The empty space is main thread work that is mostly there because of the editor version is not as optimized as the compiled. As far as my knowledge goes a lot of the time that is visible on the empty space is stripped out in the final build which is around 3-5 times faster than the editor version.
The algorithm is made so that the more queries you add the faster it gets. Since each query gets its own thread. Also the algorithm is my own version of the boids simulation algorithm found in the Unity examples.