mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-10 09:42:29 +00:00
[MIRROR] Micro-optimize GetIdFromArguments to be 48% faster, gaining 0.48s of init time on local (likely more in prod) [MDB IGNORE] (#16039)
* Micro-optimize GetIdFromArguments to be 48% faster, gaining 0.48s of init time on local (likely more in prod) (#69659) About The Pull Request Avoids stringifying key unless its necessary. This was done redundantly twice, but I locked it to just the isnum path, as REF will always return a string, and the other path passes istext. Use sortTim directly instead of sort_list. sort_list is just sortTim but it copies the list, so it's just wasted cost. I still would like the bespoke element key option, as that's the only way to drastically cut down costs on things like item descriptions and decals, but this is good for the general use case, and makes it marginally less pressing. I also want to test if we'd be better off inserting into the list in sorted order rather than sorting it all in the end, but I suspect not. * Micro-optimize GetIdFromArguments to be 48% faster, gaining 0.48s of init time on local (likely more in prod) Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
This commit is contained in:
@@ -33,22 +33,28 @@ PROCESSING_SUBSYSTEM_DEF(dcs)
|
||||
var/datum/element/eletype = arguments[1]
|
||||
var/list/fullid = list("[eletype]")
|
||||
var/list/named_arguments = list()
|
||||
|
||||
for(var/i in initial(eletype.id_arg_index) to length(arguments))
|
||||
var/key = arguments[i]
|
||||
var/value
|
||||
|
||||
if(istext(key))
|
||||
value = arguments[key]
|
||||
if(!(istext(key) || isnum(key)))
|
||||
key = REF(key)
|
||||
key = "[key]" // Key is stringified so numbers dont break things
|
||||
if(!isnull(value))
|
||||
if(!(istext(value) || isnum(value)))
|
||||
value = REF(value)
|
||||
named_arguments["[key]"] = value
|
||||
else
|
||||
var/value = arguments[key]
|
||||
if (isnull(value))
|
||||
fullid += key
|
||||
else
|
||||
if (!istext(value) && !isnum(value))
|
||||
value = REF(value)
|
||||
named_arguments[key] = value
|
||||
|
||||
continue
|
||||
|
||||
if (isnum(key))
|
||||
fullid += "[key]"
|
||||
else
|
||||
fullid += REF(key)
|
||||
|
||||
if(length(named_arguments))
|
||||
named_arguments = sort_list(named_arguments)
|
||||
named_arguments = sortTim(named_arguments, /proc/cmp_text_asc)
|
||||
fullid += named_arguments
|
||||
|
||||
return list2params(fullid)
|
||||
|
||||
Reference in New Issue
Block a user