Transform Fixes - Free Performance

I wasn’t originally going to post this, but got asked to share it.

Disclaimer: While I can say with confidence these bring performance improvements, I can’t accurately say how much as the project which exposes these issues has a compounding effect on performance gains.

A few months back I made a thread about optimizing LocalToParentSystem. That’s the system that schedules the UpdateHierarchy job and eats up half your frame budget if you instantiate a bunch of prefabs with entity hierarchies. And while the system got the ISystem and Burst treatment, it still contains a bug which causes a race condition on the LocalToWorld change filter and makes it update some unchanged transforms. Not only do I fix that bug, but I made it skip fetching the LocalToWorld from parents when neither the parent nor child is updated. I have never seen an instance where this runs slower.

A second issue is with CopyInitialTransformFromGameObjectSystem, which is missing requiring its only EntityQuery for update. There’s a second hidden EntityQuery created by IJobEntity which causes the system to run every frame.

The third issue is the most mind-boggling. ParentSystem stood to receive the biggest benefit from being an ISystem with Burst, since it actually does quite a bit of work on the main thread. However, it contains IJob instances and schedules them, and that apparently doesn’t work in an ISystem, so Burst is disabled across the entire OnUpdate(). The dumb part? Every instance of an IJob in the system is scheduled and then immediately completed. At that point, it might as well just run on the main thread. So instead of scheduling and completing those jobs, I just run Execute on them directly, and then enable Burst for the entire system. I then also changed some RemoveAt() calls to use RemoveAtSwapBack(). Now the system spends the majority of its time doing structural changes. You’ll see the biggest improvement with lots of children entities being created and destroyed with wide hierarchies.

If you want to play with these improvements yourself, you can grab the files from this commit: Improved Transforms Act 1 · Dreaming381/lsss-wip@e8a3b43 · GitHub
If you remove the [DisableAutoCreation] they will automatically install themselves into the correct spot and disable the systems they are replacing. They shouldn’t have any other dependencies in the project.

16 Likes

This looks really promising.