Help with mod optimization
Posted: Sun Mar 26, 2017 9:01 am
My mod currently takes 0.030 ms of calculation time only to check if some global/ locals exist. Is there a way to make this process less performance intensive?
Even if global.portal1.entity/global.portal2.entity don't exist the process takes about 0.029 ms. If they exist but aren't valid, the process takes about 0.032 ms, so it feels weird to me that cheking if they exist takes much longer than checking if they are valid. Doing this less often also doesn't increase performancce, the number stays around 0.028-0.030 ms.
Code: Select all
script.on_event(defines.events.on_tick, function(event)
if event.tick % 5 == 0 then
local p1 = global.portal1.entity
local p2 = global.portal2.entity
if p1 and p2 then
if p1.valid and p2.valid then
for index, player in pairs(game.players) do
if player.connected and player.character and player.vehicle == nil then
try_teleport_1(player)
try_teleport_2(player)
end
end
end
end
end
end)