From fcade1b1403df7270f2b7e7213d6c7f05afd1cb4 Mon Sep 17 00:00:00 2001 From: Kylerace Date: Sun, 16 Mar 2025 17:42:36 -0700 Subject: [PATCH] fixes tech disk uploading taking 5 seconds of total cpu (#90005) ## About The Pull Request idk if the master crash thing was effectively solved in the last week but now it is, uploading the debug tech disk has gone from 5 seconds of total cpu to 0.58 seconds. also since it filters out already added designs and nodes more it costs much less to upload it redundantly than before. before (uploading disk to web and web to disk) [message(5).txt](https://github.com/user-attachments/files/19205791/message.5.txt) uploading 1 time [message(3).txt](https://github.com/user-attachments/files/19205746/message.3.txt) uploading 7 times [message(4).txt](https://github.com/user-attachments/files/19205756/message.4.txt) ## Why It's Good For The Game why did it take 5 seconds to go over 1000 things? because it was redundantly doing things 10,000s of times ## Changelog :cl: refactor: tech disk uploading isnt super slow anymore (much harder to crash spacetime with it) /:cl: --------- Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> --- code/modules/research/machinery/_production.dm | 11 +++++++---- code/modules/research/techweb/_techweb.dm | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/code/modules/research/machinery/_production.dm b/code/modules/research/machinery/_production.dm index 5fd5f3fcd35..376f45d5bc1 100644 --- a/code/modules/research/machinery/_production.dm +++ b/code/modules/research/machinery/_production.dm @@ -21,8 +21,10 @@ var/stripe_color = null ///direction we output onto (if 0, on top of us) var/drop_direction = 0 - //looping sound for printing items + ///looping sound for printing items var/datum/looping_sound/lathe_print/print_sound + ///made so we dont call addtimer() 40,000 times in on_techweb_update(). only allows addtimer() to be called on the first update + var/techweb_updating = FALSE /obj/machinery/rnd/production/Initialize(mapload) print_sound = new(src, FALSE) @@ -108,6 +110,7 @@ /// Updates the list of designs this fabricator can print. /obj/machinery/rnd/production/proc/update_designs() PROTECTED_PROC(TRUE) + techweb_updating = FALSE var/previous_design_count = cached_designs.len @@ -130,9 +133,9 @@ /obj/machinery/rnd/production/proc/on_techweb_update() SIGNAL_HANDLER - // We're probably going to get more than one update (design) at a time, so batch - // them together. - addtimer(CALLBACK(src, PROC_REF(update_designs)), 2 SECONDS, TIMER_UNIQUE | TIMER_OVERRIDE) + if(!techweb_updating) //so we batch these updates together + techweb_updating = TRUE + addtimer(CALLBACK(src, PROC_REF(update_designs)), 2 SECONDS) ///When materials are instered via silo link /obj/machinery/rnd/production/proc/silo_material_insert(obj/machinery/rnd/machine, container, obj/item/item_inserted, last_inserted_id, list/mats_consumed, amount_inserted) diff --git a/code/modules/research/techweb/_techweb.dm b/code/modules/research/techweb/_techweb.dm index 3da8fe4e1c9..589cdf310e6 100644 --- a/code/modules/research/techweb/_techweb.dm +++ b/code/modules/research/techweb/_techweb.dm @@ -149,10 +149,10 @@ CHECK_TICK if(get_available_nodes()[i] || get_researched_nodes()[i] || get_visible_nodes()[i]) receiver.hidden_nodes -= i //We can see it so let them see it too. - for(var/i in researched_nodes) + for(var/i in researched_nodes - receiver.researched_nodes) CHECK_TICK receiver.research_node_id(i, TRUE, FALSE, FALSE) - for(var/i in researched_designs) + for(var/i in researched_designs - receiver.researched_designs) CHECK_TICK receiver.add_design_by_id(i) receiver.recalculate_nodes() @@ -486,7 +486,7 @@ return if(researched) researched_nodes[node.id] = TRUE - for(var/id in node.design_ids) + for(var/id in node.design_ids - researched_designs) add_design(SSresearch.techweb_design_by_id(id)) else if(available)