tgstation/-tg-station — pull request #2937 by MrPerson (2014-02-28 08:50:43+00:00)
Title: qdel() garbage collection system [WIP]

Taken from /vg/ (thanks N3X15), a system to delete things much faster than del() via garbage collection.

Works ok on most things but there are some issues:
[ ] Pipes don't GC, which makes the whole system kind of pointless from a speed pov
[ ] Mobs that get GC'd after the round starts always fail and need to be force del(). Even simple animals. Luckily the gib() and ghostize() procs handle everything so it doesn't look stupid. Tempted to just del() them and get it over with.
[ ] I believe there's still some debug shit left around. I'll fix that at some point. I know there's a qdel_test() verb all mobs have left so don't run any large scale tests unless you trust your players a lot.
[ ] There's some runtimes associated with qdel()'d objects and spawn()'d code. Low prio until pipes get working.
[ ] Lots of things can't GC correctly because of dangling references. Mostly in the signal controller. Still need to find the rest of these, but they're hard to find in the logs between the literal hundreds of pipes.

Good news: Things are fast until the lag from force del() hits. Cables GC correctly. new_players GC correctly. Mining mobs qdel()'d BEFORE the round starts GC correctly. Rounds take a bit less time to start up and bombs/singulo are hella fast. There may be gains from general bumps on a live server but we're nowhere near that state yet.

Changes:
Do not use Del() anymore for behavior on delete. Do that in Destroy(). Make sure to call the super or else the object won't GC!
Do not use del(atom/movable) anymore unless you absolutely have to. If you can, call qdel(atom/movable) instead.
The GC's workflow is basically when told to qdel() an object, null out all its vars on the next tick. Next, it stores the object's \ref[] and the time it was deleted in a list. Then, after 30 seconds have passed, check to make sure the object is actually deleted. If it's gone, good, cut it and move on. If it's not, del() it. There's safeties to make sure not too many var nullings are done a tick, not too many deletion checks, and not too many force del()'s get done. They're all defines so changing them is super easy.

What I need, in order of importance.
Help getting pipes to GC. Based on debug feedback, I know pipes are winding up in multiple pipelines and pipenets. This is really annoying and the biggest hurdle by far. A port of /vg/'s atmospherics code would be wonderful.
Comments and other feedback, although I would suggest mostly reading controllers/garbage.dm, game/atom.dm, and game/atoms_movable.dm and commenting on the workflow there. Most everything else is literally just replace del with qdel, replace Del() with Destroy().
Help getting mobs to GC.
More reports on the kinds of thing that fail to GC and what causes runtimes when qdel()'d.

This is nowhere near ready to merge or whatever, but I'm putting this up anyways so everyone can look/comment/whatever.