Initial GC fixes/tweaks/cleanup/documenting

This commit is contained in:
Krausus
2015-06-27 01:56:57 -04:00
parent 4d9baf9936
commit b386cec388
19 changed files with 444 additions and 285 deletions
@@ -25,14 +25,3 @@
world << "Diary: \[[diaryType]:[type]] [text]"
else
world << "Log: \[[type]] [text]"
/**
* var/disposed
*
* In goonstation, disposed is set to 1 after an object enters the delete queue
* or the object is placed in an object pool (effectively out-of-play so to speak)
*/
/datum/var/disposed
// Garbage collection (controller).
/datum/var/gcDestroyed
/datum/var/timeDestroyed
@@ -31,7 +31,7 @@ datum/updateQueueWorker/proc/doWork()
var/datum/object = objects[objects.len] // Pull out the object
objects.len-- // Remove the object from the list
if (istype(object) && !isturf(object) && !object.disposed && isnull(object.gcDestroyed)) // We only work with real objects
if (istype(object) && !isturf(object) && isnull(object.gcDestroyed)) // We only work with real objects
call(object, procName)(arglist(arguments))
// If there's nothing left to execute
+3 -2
View File
@@ -8,7 +8,7 @@
//#endif
for(var/obj/machinery/M in machines)
if(M && !M.gcDestroyed)
if(M && isnull(M.gcDestroyed))
#ifdef PROFILE_MACHINES
var/time_start = world.timeofday
#endif
@@ -29,6 +29,7 @@
machine_profiling[M.type] += (time_end - time_start)
#endif
else
machines -= M
scheck()
+3 -3
View File
@@ -4,9 +4,9 @@
/datum/controller/process/pipenet/doWork()
for(var/datum/pipe_network/pipeNetwork in pipe_networks)
if(istype(pipeNetwork) && !pipeNetwork.disposed)
if(istype(pipeNetwork) && isnull(pipeNetwork.gcDestroyed))
pipeNetwork.process()
scheck()
continue
pipe_networks.Remove(pipeNetwork)
else
pipe_networks -= pipeNetwork
+6 -11
View File
@@ -8,18 +8,15 @@ var/global/list/power_machinery_profiling = list()
schedule_interval = 20 // every 2 seconds
/datum/controller/process/power_machinery/doWork()
for(var/i = 1 to power_machines.len)
if(i > power_machines.len)
break
var/obj/machinery/M = power_machines[i]
if(istype(M) && !M.gcDestroyed)
for(var/obj/machinery/M in power_machines)
if(istype(M) && isnull(M.gcDestroyed))
#ifdef PROFILE_MACHINES
var/time_start = world.timeofday
#endif
if(M.process() == PROCESS_KILL)
M.inMachineList = 0
power_machines.Remove(M)
power_machines -= M
continue
if(M && M.use_power)
@@ -34,12 +31,10 @@ var/global/list/power_machinery_profiling = list()
power_machinery_profiling[M.type] += (time_end - time_start)
#endif
else
if(!power_machines.Remove(M))
power_machines.Cut(i,i+1)
power_machines -= M
else
if(M)
if(istype(M))
M.inMachineList = 0
if(!power_machines.Remove(M))
power_machines.Cut(i,i+1)
power_machines -= M
scheck()
+3 -3
View File
@@ -4,9 +4,9 @@
/datum/controller/process/powernet/doWork()
for(var/datum/powernet/powerNetwork in powernets)
if(istype(powerNetwork) && !powerNetwork.disposed)
if(istype(powerNetwork) && isnull(powerNetwork.gcDestroyed))
powerNetwork.reset()
scheck()
continue
powernets.Remove(powerNetwork)
else
powernets -= powerNetwork
-201
View File
@@ -1,201 +0,0 @@
#define GC_COLLECTIONS_PER_TICK 300 // Was 100.
#define GC_COLLECTION_TIMEOUT (30 SECONDS)
#define GC_FORCE_DEL_PER_TICK 60
//#define GC_DEBUG
var/list/gc_hard_del_types = list()
var/datum/garbage_collector/garbageCollector
/client/proc/gc_dump_hdl()
set name = "(GC) Hard Del List"
set desc = "List types that are hard del()'d by the GC."
set category = "Debug"
if(!check_rights(R_DEBUG))
return
if(!gc_hard_del_types || !gc_hard_del_types.len)
usr << "<span class='notice'>No hard del()'d types found.</span>"
for(var/A in gc_hard_del_types)
usr << "[A] = [gc_hard_del_types[A]]"
/datum/garbage_collector
var/list/queue = new
var/del_everything = 0
// To let them know how hardworking am I :^).
var/dels_count = 0
var/hard_dels = 0
var/soft_dels = 0
/datum/garbage_collector/proc/addTrash(const/atom/movable/AM)
if(!istype(AM))
return
if(del_everything)
del(AM)
hard_dels++
dels_count++
return
queue["\ref[AM]"] = world.timeofday
/datum/garbage_collector/proc/process()
var/remainingCollectionPerTick = GC_COLLECTIONS_PER_TICK
var/remainingForceDelPerTick = GC_FORCE_DEL_PER_TICK
var/collectionTimeScope = world.timeofday - GC_COLLECTION_TIMEOUT
while(queue.len && --remainingCollectionPerTick >= 0)
var/refID = queue[1]
var/destroyedAtTime = queue[refID]
if(destroyedAtTime > collectionTimeScope)
break
var/atom/movable/AM = locate(refID)
if(AM) // Something's still referring to the qdel'd object. del it.
if(isnull(AM.gcDestroyed))
queue -= refID
continue
if(remainingForceDelPerTick <= 0)
break
#ifdef GC_DEBUG
WARNING("gc process force delete [AM.type]")
#endif
AM.hard_deleted = 1
gc_hard_del_types |= AM.type
del AM
hard_dels++
remainingForceDelPerTick--
#ifdef GC_DEBUG
#undef GC_DEBUG
#endif
#undef GC_FORCE_DEL_PER_TICK
#undef GC_COLLECTION_TIMEOUT
#undef GC_COLLECTIONS_PER_TICK
/datum/garbage_collector/proc/dequeue(id)
if (queue)
queue -= id
dels_count++
/datum/garbage_collector/proc/hardDel(const/datum/D)
WARNING("GC hard-delling [D.type].")
gc_hard_del_types |= D.type
del(D)
garbageCollector.hard_dels++
garbageCollector.dels_count++
/*
* NEVER USE THIS FOR ANYTHING OTHER THAN /atom/movable
* OTHER TYPES CANNOT BE QDEL'D BECAUSE THEIR LOC IS LOCKED OR THEY DON'T HAVE ONE.
*/
/proc/qdel(var/datum/D, ignore_pooling = 0)
if(isnull(D))
return
if(isnull(garbageCollector))
del(D)
return
if(!istype(D))
WARNING("qdel() passed object of type [D.type]. qdel() can only handle /datum/ types.")
del(D) //no clue what could even do this, but just in case.
return
if(isnull(D.gcDestroyed))
// Let our friend know they're about to get fucked up.
var/hint = D.Destroy()
switch(hint)
if(QDEL_HINT_QUEUE) //qdel should queue the object for deletion
garbageCollector.addTrash(D)
if(QDEL_HINT_LETMELIVE) //qdel should let the object live after calling destroy.
return
if(QDEL_HINT_IWILLGC) //functionally the same as the above. qdel should assume the object will gc on its own, and not check it.
return
if (QDEL_HINT_HARDDEL_NOW) //qdel should assume this object won't gc, and hard del it post haste.
garbageCollector.hardDel(D)
if (QDEL_HINT_PUTINPOOL) //qdel will put this object in the pool.
PlaceInPool(D,0)
else
// world << "WARNING GC DID NOT GET A RETURN VALUE FOR [D], [D.type]!"
garbageCollector.addTrash(D)
/datum/controller
var/processing = 0
var/iteration = 0
var/processing_interval = 0
/datum/controller/proc/recover() // If we are replacing an existing controller (due to a crash) we attempt to preserve as much as we can.
/*
* Like Del(), but for qdel.
* Called BEFORE qdel moves shit.
*/
/datum/proc/Destroy()
return QDEL_HINT_HARDDEL_NOW //qdel can't handle datums, therefore tell it to immediately del
/client/proc/qdel_toggle()
set name = "Toggle qdel Behavior"
set desc = "Toggle qdel usage between normal and force del()."
set category = "Debug"
garbageCollector.del_everything = !garbageCollector.del_everything
world << "<b>GC: qdel turned [garbageCollector.del_everything ? "off" : "on"].</b>"
log_admin("[key_name(usr)] turned qdel [garbageCollector.del_everything ? "off" : "on"].")
message_admins("\blue [key_name(usr)] turned qdel [garbageCollector.del_everything ? "off" : "on"].", 1)
/*/client/var/running_find_references
/atom/verb/find_references()
set category = "Debug"
set name = "Find References"
set background = 1
set src in world
if(!usr || !usr.client)
return
if(usr.client.running_find_references)
testing("CANCELLED search for references to a [usr.client.running_find_references].")
usr.client.running_find_references = null
return
if(alert("Running this will create a lot of lag until it finishes. You can cancel it by running it again. Would you like to begin the search?", "Find References", "Yes", "No") == "No")
return
qdel(src)
// Remove this object from the list of things to be auto-deleted.
if(garbageCollector)
garbageCollector.queue -= "\ref[src]"
usr.client.running_find_references = type
testing("Beginning search for references to a [type].")
var/list/things = list()
for(var/client/thing)
things += thing
for(var/datum/thing)
things += thing
for(var/atom/thing)
things += thing
for(var/event/thing)
things += thing
testing("Collected list of things in search for references to a [type]. ([things.len] Thing\s)")
for(var/datum/thing in things)
if(!usr.client.running_find_references) return
for(var/varname in thing.vars)
var/variable = thing.vars[varname]
if(variable == src)
testing("Found [src.type] \ref[src] in [thing.type]'s [varname] var.")
else if(islist(variable))
if(src in variable)
testing("Found [src.type] \ref[src] in [thing.type]'s [varname] list var.")
testing("Completed search for references to a [type].")
usr.client.running_find_references = null
*/
+10 -2
View File
@@ -10,6 +10,13 @@ var/global/last_tick_duration = 0
var/global/air_processing_killed = 0
var/global/pipe_processing_killed = 0
/datum/controller
var/processing = 0
var/iteration = 0
var/processing_interval = 0
/datum/controller/proc/recover() // If we are replacing an existing controller (due to a crash) we attempt to preserve as much as we can.
datum/controller/game_controller
var/breather_ticks = 2 //a somewhat crude attempt to iron over the 'bumps' caused by high-cpu use by letting the MC have a breather for this many ticks after every loop
var/minimum_ticks = 20 //The minimum length of time between MC ticks
@@ -288,12 +295,13 @@ datum/controller/game_controller/proc/process()
/datum/controller/game_controller/proc/process_bots()
for(var/obj/machinery/bot/Bot in aibots)
if(!Bot.gc_destroyed)
if(Bot && isnull(Bot.gcDestroyed))
last_thing_processed = Bot.type
spawn(0)
Bot.bot_process()
continue
aibots -= Bot
else
aibots -= Bot
/datum/controller/game_controller/proc/processObjects()
for (var/obj/Object in processing_objects)