Created
February 28, 2022 04:40
-
-
Save MrStonedOne/cfeb8ba5e8326cf524d156cd780df45c to your computer and use it in GitHub Desktop.
typecache vs istype realworld
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typecache_size=1 istype_size=1 count = 2102 typecache = 0.00486952 istype = 0.0100201 | |
typecache_size=2 istype_size=2 count = 27 typecache = 0.00527306 istype = 0.00397598 | |
typecache_size=3 istype_size=1 count = 257 typecache = 0.00114017 istype = 0.00145129 | |
typecache_size=4 istype_size=1 count = 15 typecache = 0.0031474 istype = 0.00425723 | |
typecache_size=4 istype_size=4 count = 20 typecache = 0.00287879 istype = 0.00792816 | |
typecache_size=9 istype_size=1 count = 4 typecache = 0.00223673 istype = 0.00292081 | |
typecache_size=19 istype_size=2 count = 18 typecache = 0.00152456 istype = 0.00148972 | |
typecache_size=20 istype_size=3 count = 5900 typecache = 0.0023313 istype = 0.00363955 | |
typecache_size=29 istype_size=4 count = 270 typecache = 0.00289221 istype = 0.00459528 | |
typecache_size=32 istype_size=5 count = 179054 typecache = 0.00272347 istype = 0.0050234 | |
typecache_size=44 istype_size=2 count = 155 typecache = 0.0367967 istype = 0.16274 | |
typecache_size=62 istype_size=1 count = 28 typecache = 0.00387578 istype = 0.00423839 | |
typecache_size=68 istype_size=13 count = 208 typecache = 0.00340232 istype = 0.00945927 | |
typecache_size=166 istype_size=4 count = 241 typecache = 0.00293313 istype = 0.00440353 | |
typecache_size=495 istype_size=1 count = 5 typecache = 0.0055791 istype = 0.00531111 | |
typecache_size=1646 istype_size=2 count = 20 typecache = 0.00518068 istype = 0.00553224 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Profile results (total time) | |
Proc Name Self CPU Total CPU Real Time Overtime Calls | |
---------------------------------------------------------------------------------------------- --------- --------- --------- --------- --------- | |
/proc/typecacheof 0.002 0.002 0.002 0.000 41 | |
/proc/typecache_filter_list_typecache 0.385 0.391 0.440 0.000 186611 | |
/proc/typecache_filter_list_istype 1.069 1.081 1.137 0.001 186611 | |
/proc/typecache_filter_list 3.587 96.530 96.559 0.000 186611 | |
/proc/simplify_type_list 88.975 91.486 91.520 0.228 186611 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///238 of _lists.dm, only modified lines shown. | |
///Checks for specific types in specifically structured (Assoc "type" = TRUE|FALSE) lists ('typecaches') | |
#define is_type_in_typecache(A, L) (A && length(L) && (ispath(A) ? L[A] : length(typecache_filter_list(list(A), L)))) | |
GLOBAL_LIST_INIT(filter_list_profile, list()) | |
/proc/simplify_type_list_condition_1() | |
return . | |
/proc/simplify_type_list_condition_2() | |
return . | |
/proc/simplify_type_list_loop_1() | |
return . | |
/proc/simplify_type_list(list/typecache) | |
. = typecache.Copy() | |
for (var/typepath in typecache) | |
simplify_type_list_loop_1() | |
var/list/subtypes = subtypesof(typepath) | |
var/list/common = (subtypes & typecache) | |
if (length(common) == length(subtypes)) | |
simplify_type_list_condition_1() | |
. -= subtypes | |
if (length(.) == length(typecache)) | |
simplify_type_list_condition_2() | |
///returns a new list with only atoms that are in the typecache list | |
/proc/typecache_filter_list(list/atoms, list/typecache) | |
typecache = typecache.Copy() | |
var/list/simple_list = simplify_type_list(typecache) | |
var/itemstr = "typecache_size=[length(typecache)] istype_size=[length(simple_list)]" | |
var/list/profileitem = GLOB.filter_list_profile[itemstr] | |
if (!profileitem) | |
profileitem = GLOB.filter_list_profile[itemstr] = list("count" = 0) | |
profileitem["count"]++ | |
var/cost = TICK_USAGE_REAL | |
. = typecache_filter_list_typecache(atoms, typecache) | |
cost = TICK_USAGE_TO_MS(cost) | |
if (!profileitem["typecache"]) | |
profileitem["typecache"] = cost | |
else | |
profileitem["typecache"] = MC_AVERAGE(profileitem["typecache"], cost) | |
cost = TICK_USAGE_REAL | |
. = typecache_filter_list_istype(atoms, simple_list) | |
cost = TICK_USAGE_TO_MS(cost) | |
if (!profileitem["istype"]) | |
profileitem["istype"] = cost | |
else | |
profileitem["istype"] = MC_AVERAGE(profileitem["istype"], cost) | |
/proc/typecache_filter_list_typecache(list/atoms, list/typecache) | |
RETURN_TYPE(/list) | |
. = list() | |
for(var/atom/atom_checked as anything in atoms) | |
if (typecache[atom_checked.type]) | |
. += atom_checked | |
/proc/typecache_filter_list_istype(list/atoms, list/typecache) | |
RETURN_TYPE(/list) | |
. = list() | |
for(var/atom/atom_checked as anything in atoms) | |
for (var/typepath in typecache) | |
if (istype(atom_checked, typepath)) | |
. += atom_checked | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment