for(var/obj/machinery/door/D in world)
is quite slow because it loops over all objs (or all atoms) in the world, so Goonstation has come up with some annoying workaround - they make a list of all atoms of each type they want to loop over.
I suggest that it should be the engine's job to make it work fast, not the developer's job. It would require adding two pointers to each atom, forming a linked list through all atoms of the same type. Subtypes could be handled by looping over subtypes, since subtypes are usually much less numerous than objects.
Alternatively, the compiler could look at which types are used in for loops (since it can see all the loops) and create a list for each of those types and its subtypes. That would avoid looping over subtypes, but may increase memory usage more. I expect that memory usage won't be a problem either way.
This sounds like the only solution that makes sense. If you want to loop over very specific sets of objects, why wouldn't you have to keep track of them?