How can I optimize the Initialization of A*? (mobile)


I’m working on reducing peak performance spikes in my Android game. It turns out that some of the initialization functions of A* consume too much. I don’t actually need the loading to be instantaneous—it could take several seconds without any issues. By the way, I am using cached data, there is no scan in realtime.

For instance, the DeserializeGraphs function can take up to 300ms, accounting for 70% of the loading cost of a scene.

I’ve searched the forum, but I don’t think anyone has addressed this performance cost issue during initialization. Is there a way to perform the initialization, or a large part of it, outside of the Main Thread?

I’ve run some tests, but apparently it needs to be on the Main Thread to access GameObjects, etc. What I have managed to do is split some calls into a coroutine, waiting a few frames between each one, which has smoothed out the loading. However, the aforementioned function, “DeserializeGraphs”, is the most resource-intensive and runs all at once.

I hope I’ve explained myself well. Many thanks in advance!

Best regards.