Hi, I am having issues with reduced in-Editor performance of native collections and quaternion from the mathematics package.
I’ve started trying to optimise some code using Burst, so I put my data into native collections. I’ve done performance testing and found native collections to be much slower in-Editor when compared with managed alternatives, which is why I have mostly avoided them. For example, I have found NativeArray to take 5x as long to loop over vs. managed arrays, which is mitigated by using pointers with NativeArray - so now I use pointers for in-Editor performance. In builds, the NativeArray is on-par with managed arrays, and is even faster when using Burst.
This slowness in-Editor also applies to other native collections I have tested. Perhaps it is related to collection safety checks, which I believe to be force-enabled in-Editor, and disabled in builds.
This is all great for builds, but I do most testing in-Editor so that I can work on things and make changes, and this performance overhead can be quite substantial, and makes it difficult to understand the performance of my game. I know builds should be profiled, but if I have to profile a build every time just because the performance characteristics of these packages are completely different in builds, then this introduces a lot more wait time. I have not noticed such a large discrepancy between Editor and Build performance in other areas of my code.
I have now found that using mathematics.quaternion.LookRotation takes about 3x as long as UnityEngine.Quaternion.LookRotation in-Editor, whereas in a build, mathematics.quaternion is a bit faster even without Burst. Deep Profiling shows the bulk of the cost of mathematics.quaternion.LookRotation in-Editor to be from the constructor.
In my case I am making an open world game, and am currently optimising my enemy system, which has many spawned enemies.
I’m wondering if you have any recommendations here, if you have noticed this, and how you are working with it; and if Unity can make any improvements to the Editor performance of these packages.
EDIT: I am using mathematics 1.2.6 and collections 1.4.0. I see that I can update the collections package so I will look into that.