Code:
//-- Preloading ----------------------------------------------------------------
turf
var
dmm_suite/preloader/dmm_preloader
atom/New(newLoc)
if(istype(newLoc, /turf))
var /turf/turfLoc = newLoc
if(turfLoc.dmm_preloader)
turfLoc.dmm_preloader.load(src)
. = ..()
dmm_suite
preloader
parent_type = /datum
var
list/attributeKeys
list/attributeValues
turf/location
New(turf/loadLocation, list/_attributeKeys, list/_attributeValues)
loadLocation.dmm_preloader = src
attributeKeys = _attributeKeys
attributeValues = _attributeValues
proc
load(atom/what) // All CPU spends all its time here.
if(!what) del src
var keyLen = attributeKeys.len
for(var/I = 1 to keyLen)
what.vars[attributeKeys[I]] = attributeValues[I]
del src
Problem description:
This is taken from a larger map loading system. Specifically, an update of my dmm_suite library. That load function is taking 7/8th of all time spent loading maps, and I've never looked much into optimizing DM so I don't know why. I'm guessing it has something to do with indexing variables by string, but I don't know how to get around that considering my use case.
The idea is that I need to set values on any loaded atoms before any custom code in New() is executed. The variables to be loaded could be absolutely anything the developer defines on an atom.
Originally I had one associative list for attribute keys => values, but the version above performed slightly better. Any ideas?
Ditch this.
That's as close to optimal as it's gonna get without blowing up the rest of your suite and rewriting the whole thing. I can't promise that preloaders aren't still dropping into worst-case deletion behavior. I don't know the rest of your suite. Read the developer reference on Garbage collection and the del proc. I rewrote part of that section and Lummox revised it as well. It'll open your eyes to what's happening.