Page 1 of 1

[boskid][2.0.28] High CPU time in "Electric Network" after creating and destroying many space platforms

Posted: Sun Dec 22, 2024 5:48 pm
by jeff.s
After creating and destroying a large number of space platforms, there is abnormally high CPU usage for "Electric network" despite there no longer being any space platforms. This also increases the size of the save file.

The issue persists across reload and restarting the game. I checked this both on the MacOS build (M2 laptop) and the Windows build.

Steps to reproduce

1. Start a new game
2. Open F4 debug menu and enable "show time usage"
3. Create and destroy a large number of space platforms by running this:

Code: Select all

/c
storage.x=0
script.on_nth_tick(1,function()
  storage.x=storage.x+1
  if storage.x > 100000 then return end
  local p = game.forces.player.create_space_platform({name='p'..storage.x,planet='nauvis',starter_pack='space-platform-starter-pack'})
  p.apply_starter_pack()
  p.destroy(10)
end)
4. Observe that "Electric Network" CPU time usage is seemingly linearly increasing
5. Open editor and observe that there are no surfaces aside from Nauvis

Code: Select all

Update: 20.884/17.498/22.520
  Latency update: 0
  Game update: 20.864/17.466/22.495
    Planets update: 0.001/0.000/0.003
    Control behaviors (MT): 0.059/0.016/0.184
    Transport lines (MT): 0.068/0.024/0.145
    Electric+Heat+Fluid+Circuit (MT): 20.714/17.315/22.311
      Electric network: 18.488/15.148/20.101
      Heat network: O
    Fluid flow: 0.000/0.000/0.020
    Entity update: 0.004/0.003/0.026
    Lightning update: 0
    Tile heating update: 0
Here's a save file you can open which will have high CPU usage:
enetwork bug.zip
(2.13 MiB) Downloaded 11 times

Re: [2.0.28] High CPU time for "Electric Network" after creating and destroying a large number of space platforms

Posted: Sun Dec 22, 2024 5:53 pm
by jeff.s
Rseding pointed out it might be the global network not getting destroyed. Indeed if I manually destroy it I don't see the same behavior:

Code: Select all

/c
storage.x=0
script.on_nth_tick(1,function()
  storage.x=storage.x+1
  if storage.x > 100000 then return end
  local p = game.forces.player.create_space_platform({name='p'..storage.x,planet='nauvis',starter_pack='space-platform-starter-pack'})
  p.apply_starter_pack()
  p.surface.destroy_global_electric_network()
  p.destroy(10)
end)

Re: [boskid][2.0.28] High CPU time in "Electric Network" after creating and destroying many space platforms

Posted: Sun Dec 22, 2024 8:01 pm
by boskid
Indeed. Fixed for 2.0.29.