Deserializing graph is both 80% slower and creates 200% more GC than NavmeshPrefab?

  • A* version: 5.4.6
  • Unity version: 6000.3.11f1

Hello, we have some mid sized maps we load in at runtime. Scanning was causing a bit of lag so switched to using the NavmeshPrefab where we just save the whole graph for each NavmeshPrefab. But in profiling I noticed that the ReplaceTiles() method ends up doing a lot of things that (seem) to be not needed when the graph is just being replaced.

So I realized I could just serialize the nodes and the graph as a whole to avoid this. But it was much worse.

NavmeshPrefab: 2.9MB | 15.74ms.
Deserialize: 7.8MB | 27.64ms

Serialization is:
AstarPath.active.data.SerializeGraphs(SerializeSettings.NodesAndSettings);

Then saving to a file just like NavmeshPrefab.
And deserialization is:
AstarPath.Active.data.DeserializeGraphsAdditive(SerializedNavmesh.bytes);

So I guess I was wondering if there is any recommendations for how to best bake and then load a graph at runtime? My plan would be to maybe dig in more to the ReplaceTiles and see if I can work out a way to have it work without doing some of that (again seemling) not needed work. But before I wanted to see if there was a easier/better solution. Or if there is something I am doing wrong haha.

Thanks!

I’ll bring this up to Aron so he can take a look at it! I’m sure you’ve already seen this page but in case it was missed I still want to link the docs on Saving/Loading graphs

1 Like