Besides,Klonan wrote:Mooncat wrote: Statistics on my side:
When the on_tick listener was added, FPS/UPS started to drop slowly when the number of turrets reached 8k.
When the on_tick listener was removed, FPS/UPS started to drop when the number reached 18k. FPS/UPS was around 54 when there were 19k turrets.
Then, the on_tick listener was added back, FPS/UPS dropped to 34.
I couldn't say whether the number of turrets is good or not for the users, as I mainly write mods recently rather than actually playing the game. I would say it is better than I thought.
Few things to note:
- the numbers are showing the situation when ONLY ONE mod is running. I expect the actual number of modded entities before FPS/UPS starts dropping will be divided by the number of mods running the same algorithm.
- when I tried to blueprint 1k turrets and placed them at once, FPS/UPS dropped significantly and could not recover. (I doubt it is something related to the code in game.)
(Creative Mode was used for clearing out obstacles, creating the nice flat land and placing turrets. But it has been removed before testing.)
Now judge it yourself.
You function is just very plain, you can optimize it very easily, you are checking all entities on every tick, you could spread the checks across multiple ticks, or only do a check every 60 ticks, or any number of things,
The way you have done it is somewhat of the least efficient way, for example this small addition would increase performance 60 times:
Code: Select all
local function on_tick(event) for surface_name, surface_position_x in pairs(global.supportive_turrets) do for x, surface_position_y in pairs(surface_position_x) do if (x + game.tick) % 60 == 0 then for y, data in pairs(surface_position_y) do if (x + y + game.tick) % check_period == 0 then if not data.turret.valid thn if data.unit.valid then data.unit.destroy() end global.supportive_turrets[surface_name][x][y] = nil end end end end end end end
The point i am getting at, is that you shouldn't worry about this,
Have no on_tick,
Don't worry about them being destroyed, because it is highly unlikely
In all my fancy mods with creating and destroying entities, i have never had an on_tick checker,
And i have never had any complaints about the entities being destroyed by some other mod