for(var/mob/m in world) <- this executes very fast
for(var/mob/m in range(mob,10)) <- while this executes too slow
shouldn't the situation be reversed??
Also certain objects take much longer to search even though there are fewer in the map.
for(var/mob/Unit/u in world){} <- 0ms lag
for(var/obj/Town/t in world){} <- 4ms lag
Why does this happens, I have only 7 towns and around 20 Units. Maybe when searching for towns it searches all obj types??
(using 32 world size)
Copyright © 2024 BYOND Software.
All rights reserved.
For instance, searching for all /obj/Town searches through all /obj, and only applies the body of the loop if istype(t, /obj/Town). It doesn't search through mobs or any other type. So, if you have a lot more objs of any type in the world than mobs of any type, it makes sense that the search for objs would take longer.
In general, avoid searching the entire world for something, because you never know how big the world will get. If you keep a list of the things you need, then it doesn't matter how large the world will get, because you never have to filter through any of it.
Example:
As for why range() is slower, it's probably because range() has to build a list of all atoms in range before you even start to iterate through it. For a range of 10, this list would contain at least 441 turfs, an area, and some number of objs and mobs. Compared to looping over a list of mobs that (presumably) already exists internally, this is much more expensive.