It actually took me a good 30 mins to realise that what id done. Which was create a lot of /mob bots on the map (to test something) and forget to removed them. But also that the method of doing something in the game currently has the potential to do this if there are a lot of players online.
In my game at the moment, when a player begins a Duel, it adds them to a list connected to them called 'SeeDuel'. It's straight forward enough it just does += usr. Then when they connect to another person (opponent) it adds them to the list.
Now when they talk, or something is output(ed) relating to the Duel, it sweeps the world like so...
for(var/mob/M in world)
The issue that i caused was that by having a large number of mobs on an area of the map (it was probably something extreme here like 300-500) sweeping through them all to check if they should see what I was saying was eating so much CPU time that Dream Seeker took about 10-15 seconds of inactivity to finally do the M << "Something".
I have to wonder what would have happened if this was a server online...with lag etc.
The SeeDuel is also used for people viewing the Duel. So if they start watching one in progress, it add's that usrs SeeDuel to theirs. So they now see everything that player can see in outputs (plus it adds themselves of course).
I'm trying to think of a better way to do this, since it seems like it would be better not to loop through the world. I have had a few ideas but im sure that other people will probably have a better ones (since im not exactly the most code savvy, and not above asking for help when i need it).
I did consider instead of in world, doing in view(). But then there is a method for a user to "view" a Duel without being near them. This is especially important for a method of Dueling where the players are not stationary... so not really a good option.
Any input into this would be helpful. Perhaps looping through the world isnt that bad, in which case i dont need to change anything. It's just the incident caused by a large number of mobs made me start thinking.... If this is going on with lots of players on a server more or less constantly... would this be the source of lag.