More cores = more RAM?

Hello! I am using latest beta 4.3.28. In my scene I have 3 graphs:

  • 960x960 nodes, node size 0.25 layered grid graph
  • 960x960 nodes, node size 0.25 grid graph
  • 960x960 nodes, node size 0.25 grid graph

Terrain 240x240 units

So there is an option in Pathfinder settings menu: Thread count. If I use One build takes 900mb of ram.
If I use High Load then

  • on 4 cpu around it takes around 2 gb of ram
  • on16 cpu around 6 gb

Is this indended behaviour?
Thanks!

Hi

Sorry for the late reply, I have been away for some time.
Yes, each thread requires some data per node. More specifically it requires around 48 bytes per node to store among other things: which node this is, the parent in the search graph, the cost to get to that node and some other stuff. Since multiple threads and thus path searches run in parallel this data cannot be shared. You have maybe 960*960*5 = 4608000 nodes (assuming the layered grid graph has at most 3 layers), so I would expect each thread to use something like 230 mb of ram.

No problem.

So there is additional data per each thread. Is there a way to set max thread count. For example 4 threads max, then when using cpu with 1 core - its 1 thread, when using cpu with 2 cores - 2 thread and up to 4 but not greater then 4?

I am sure you do know how you can use read only data in jobs for threading, right?

That is not possible from the editor itself, but you can do something like this:

public void Awake () {
    GetComponent<AstarPath>().threadCount = ThreadCount.One;
}

Place this in a script and modify unity’s execution order settings to make sure this script is executed before the AstarPath script*. Then you can set whatever tread count you want when the game starts.
It’s a bit awkward to do it this way I know. It’s just because the script scans all graphs during Awake, so the thread counts need to be set at that point.

Of course. There is a bunch of read-only data that the threads share. This data is read/write though. It’s all the temporary data a thread needs for pathfinding purposes.

1 Like

That’s a lot of shared data. Anyway I think we can figure something out. Thanks alot!

Well you do have a lot of nodes too :wink:
For every byte stored by each node you need about 5 MB of RAM.

Yeah, I need to optimaze and remove some graphs