Performance problem from too many nodes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By homyakokryak

So, I’m making a hex based map editor.

At the moment every hex is a separate node. It’s working but gets sluggish if I have something like 100X100 grid.

What can I do to fix the situation?

:bust_in_silhouette: Reply From: eons

10000 nodes are a lot but not enough to make the tree slow by themselves, first try to find more information about your problem, use the monitor and profiler to get a better guess of where is the issue (it could be in process, events or something else).

In any case you may need to optimize your design with a system of chunks/zones/cells with groups of nodes that are enabled or disabled (in or out of the tree) with certain conditions, but what to disable will depend on what are those nodes doing and where is the bottleneck.

I ran the profiler and got this: FrameTime 0.26721, IdleTime 0.26244, none of the functions takes more than 0.00040 and there is not many of them. Monitor does not show anything weird. There is a performance spike when I generate the map, but that to be expected. I have no idea what to do next.

homyakokryak | 2019-10-14 07:45

Maybe try adding a VisibilityEnabler2D node as a child of the Camera2D? The renderer should cull nodes located outside the camera view automatically, so I’m not sure if this will help.

Calinou | 2019-10-14 13:28

:bust_in_silhouette: Reply From: homyakokryak

Figured out what was wrong. The problem, as eons has pointed out, had nothing to do with the nodes. I have a _draw() function for drawing hex grid. And, well, I was drawing all 10 000 hexes every frame, one line at a time.