Page 1 of 1

[1.1.70] Poor performance when large quantities of spidertrons congregate in one location

Posted: Sat Oct 29, 2022 8:56 pm
by jeff.s
If a large number of spidertrons attempt to stand in the same location, game update starts taking longer and longer.

Steps to reproduce:

Spawn 1000 spiders in a 2x2 chunk area (fully paved and free of any obstructions):

Code: Select all

for i=1,1000 do
  local x = -32 + 64*math.random()
  local y = -32 + 64*math.random()
  local e = game.surfaces.nauvis.create_entity({name="spidertron", position={x,y}, force=game.forces.player, create_build_effect_smoke=false})
end
This idles with entity update taking around 1.0ms. Now let's send all the spiders to stand in one spot:

Code: Select all

for _, spider in pairs(game.surfaces.nauvis.find_entities_filtered{name="spidertron"}) do 
  spider.autopilot_destination = {0,0}
end
As the spiders approach the location, entity update rapidly rises. It quickly peaks around 2500ms and then slowly settles down to about 1200ms.

Re: [1.1.70] Poor performance when large quantities of spidertrons congregate in one location

Posted: Sat Oct 29, 2022 9:14 pm
by cbhj1
I get the feeling they are all trying not to step on each other's toes, that is a lot of feet.

Re: [1.1.70] Poor performance when large quantities of spidertrons congregate in one location

Posted: Sat Oct 29, 2022 10:06 pm
by boskid
Thanks for the report. I am not seeing any crashes here so this is not a bug.

Poor performance cannot be considered as a bug unless it would be a regression. Here it is one of those "player does weird things, gets weird results" things. Under the profiler i see the code spends 85% trying to find a non colliding positions and because there are a lot of entities on some of the advanced tiles, those operations take time that is linear to the amount of entities on the advanced tile which causes your experiment to effectively become something like O(N^2) which simply does not scale well.