A few performance ports (#17137)

* Faster garbage collection

https://github.com/tgstation/tgstation/pull/62969

* MC bug fix

https://github.com/tgstation/tgstation/pull/64500

* Optimize RegisterSignal

https://github.com/tgstation/tgstation/pull/69638
This commit is contained in:
Ling
2022-12-24 17:15:52 +01:00
committed by GitHub
parent 8ff3a22f7d
commit 0c5c733cd1
4 changed files with 29 additions and 21 deletions

View File

@@ -11,9 +11,16 @@
#define QDEL_HINT_IFFAIL_FINDREFERENCE 6 //Above but only if gc fails. #define QDEL_HINT_IFFAIL_FINDREFERENCE 6 //Above but only if gc fails.
//defines for the gc_destroyed var //defines for the gc_destroyed var
#define GC_QUEUE_CHECK 1 // Defines for the ssgarbage queues
#define GC_QUEUE_HARDDELETE 2 #define GC_QUEUE_FILTER 1 //! short queue to filter out quick gc successes so they don't hang around in the main queue for 5 minutes
#define GC_QUEUE_COUNT 2 //increase this when adding more steps. #define GC_QUEUE_CHECK 2 //! main queue that waits 5 minutes because thats the longest byond can hold a reference to our shit.
#define GC_QUEUE_HARDDELETE 3 //! short queue for things that hard delete instead of going thru the gc subsystem, this is purely so if they *can* softdelete, they will soft delete rather then wasting time with a hard delete.
#define GC_QUEUE_COUNT 3 //! Number of queues, used for allocating the nested lists. Don't forget to increase this if you add a new queue stage
// Defines for the time an item has to get its reference cleaned before it fails the queue and moves to the next.
#define GC_FILTER_QUEUE 1 SECONDS
#define GC_CHECK_QUEUE 5 MINUTES
#define GC_DEL_QUEUE 10 SECONDS
#define GC_QUEUED_FOR_QUEUING -1 #define GC_QUEUED_FOR_QUEUING -1
#define GC_CURRENTLY_BEING_QDELETED -2 #define GC_CURRENTLY_BEING_QDELETED -2

View File

@@ -93,7 +93,7 @@
queue_node_priority = queue_node.queued_priority queue_node_priority = queue_node.queued_priority
queue_node_flags = queue_node.flags queue_node_flags = queue_node.flags
if (queue_node_flags & SS_TICKER) if (queue_node_flags & (SS_TICKER|SS_BACKGROUND) == SS_TICKER)
if (!(SS_flags & SS_TICKER)) if (!(SS_flags & SS_TICKER))
continue continue
if (queue_node_priority < SS_priority) if (queue_node_priority < SS_priority)

View File

@@ -6,7 +6,7 @@ SUBSYSTEM_DEF(garbage)
runlevels = RUNLEVELS_DEFAULT | RUNLEVEL_LOBBY runlevels = RUNLEVELS_DEFAULT | RUNLEVEL_LOBBY
init_order = INIT_ORDER_GARBAGE init_order = INIT_ORDER_GARBAGE
var/list/collection_timeout = list(2 MINUTES, 10 SECONDS) // deciseconds to wait before moving something up in the queue to the next level var/list/collection_timeout = list(GC_FILTER_QUEUE, GC_CHECK_QUEUE, GC_DEL_QUEUE) // deciseconds to wait before moving something up in the queue to the next level
//Stat tracking //Stat tracking
var/delslasttick = 0 // number of del()'s we've done this tick var/delslasttick = 0 // number of del()'s we've done this tick
@@ -86,10 +86,13 @@ SUBSYSTEM_DEF(garbage)
/datum/controller/subsystem/garbage/fire() /datum/controller/subsystem/garbage/fire()
//the fact that this resets its processing each fire (rather then resume where it left off) is intentional. //the fact that this resets its processing each fire (rather then resume where it left off) is intentional.
var/queue = GC_QUEUE_CHECK var/queue = GC_QUEUE_FILTER
while (state == SS_RUNNING) while (state == SS_RUNNING)
switch (queue) switch (queue)
if (GC_QUEUE_FILTER)
HandleQueue(GC_QUEUE_FILTER)
queue = GC_QUEUE_FILTER+1
if (GC_QUEUE_CHECK) if (GC_QUEUE_CHECK)
HandleQueue(GC_QUEUE_CHECK) HandleQueue(GC_QUEUE_CHECK)
queue = GC_QUEUE_CHECK+1 queue = GC_QUEUE_CHECK+1
@@ -102,8 +105,8 @@ SUBSYSTEM_DEF(garbage)
/datum/controller/subsystem/garbage/proc/HandleQueue(level = GC_QUEUE_CHECK) /datum/controller/subsystem/garbage/proc/HandleQueue(level = GC_QUEUE_FILTER)
if (level == GC_QUEUE_CHECK) if (level == GC_QUEUE_FILTER)
delslasttick = 0 delslasttick = 0
gcedlasttick = 0 gcedlasttick = 0
var/cut_off_time = world.time - collection_timeout[level] //ignore entries newer then this var/cut_off_time = world.time - collection_timeout[level] //ignore entries newer then this
@@ -176,7 +179,7 @@ SUBSYSTEM_DEF(garbage)
queue.Cut(1,count+1) queue.Cut(1,count+1)
count = 0 count = 0
/datum/controller/subsystem/garbage/proc/Queue(datum/D, level = GC_QUEUE_CHECK) /datum/controller/subsystem/garbage/proc/Queue(datum/D, level = GC_QUEUE_FILTER)
if (isnull(D)) if (isnull(D))
return return
if (level > GC_QUEUE_COUNT) if (level > GC_QUEUE_COUNT)

View File

@@ -94,28 +94,26 @@
var/list/procs = signal_procs var/list/procs = signal_procs
if(!procs) if(!procs)
signal_procs = procs = list() signal_procs = procs = list()
if(!procs[target]) var/list/target_procs = procs[target] || (procs[target] = list())
procs[target] = list()
var/list/lookup = target.comp_lookup var/list/lookup = target.comp_lookup
if(!lookup) if(!lookup)
target.comp_lookup = lookup = list() target.comp_lookup = lookup = list()
var/list/sig_types = islist(sig_type_or_types) ? sig_type_or_types : list(sig_type_or_types) for(var/sig_type in (islist(sig_type_or_types) ? sig_type_or_types : list(sig_type_or_types)))
for(var/sig_type in sig_types) if(!override && target_procs[sig_type])
if(!override && procs[target][sig_type])
stack_trace("[sig_type] overridden. Use override = TRUE to suppress this warning") stack_trace("[sig_type] overridden. Use override = TRUE to suppress this warning")
procs[target][sig_type] = proctype target_procs[sig_type] = proctype
var/list/looked_up = lookup[sig_type]
if(!lookup[sig_type]) // Nothing has registered here yet if(!looked_up) // Nothing has registered here yet
lookup[sig_type] = src lookup[sig_type] = src
else if(lookup[sig_type] == src) // We already registered here else if(looked_up == src) // We already registered here
continue continue
else if(!length(lookup[sig_type])) // One other thing registered here else if(!length(looked_up)) // One other thing registered here
lookup[sig_type] = list(lookup[sig_type]=TRUE) lookup[sig_type] = list((looked_up) = TRUE, (src) = TRUE)
lookup[sig_type][src] = TRUE
else // Many other things have registered here else // Many other things have registered here
lookup[sig_type][src] = TRUE looked_up[src] = TRUE
signal_enabled = TRUE signal_enabled = TRUE