From 9d8f34dd8d870f403e9c62c23f6500befc3b4c89 Mon Sep 17 00:00:00 2001 From: MarinaGryphon Date: Fri, 20 Aug 2021 16:55:47 -0500 Subject: [PATCH] Attempts an optimisation for power_change - Adds an alternate, hopefully faster list iteration method for machines in power_change - Removes uses of INVOKE_ASYNC for power_change, since it's slower than normal proc calls and does nothing since it doesn't sleep TODO: Diagnose what the fuck is making power_change so slow anyway. --- code/game/area/areas.dm | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index a28d558454..1d0069a7cd 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -310,7 +310,7 @@ GLOBAL_LIST_EMPTY(teleportlocs) A.power_light = FALSE A.power_equip = FALSE A.power_environ = FALSE - INVOKE_ASYNC(A, .proc/power_change) + A.power_change() STOP_PROCESSING(SSobj, src) return ..() @@ -544,15 +544,19 @@ GLOBAL_LIST_EMPTY(teleportlocs) // called when power status changes /area/proc/power_change() - for(var/obj/machinery/M in src) // for each machine in the area - M.power_change() // reverify power status (to update icons etc.) - if(sub_areas) - for(var/i in sub_areas) - var/area/A = i - A.power_light = power_light - A.power_equip = power_equip - A.power_environ = power_environ - INVOKE_ASYNC(A, .proc/power_change) + if(contents.len < GLOB.machines.len) // it would be faster to loop over contents + for(var/obj/machinery/M in src) // for each machine in the area + M.power_change() // reverify power status (to update icons etc.) + else // it would be faster to loop over the machines list + for(var/obj/machinery/M as anything in GLOB.machines) // for each machine + if(get_area(M) != src) // in the area + continue + M.power_change() // reverify power status (to update icons etc.) + for(var/area/A as anything in sub_areas) + A.power_light = power_light + A.power_equip = power_equip + A.power_environ = power_environ + A.power_change() update_appearance() /area/proc/usage(chan)