It’s number 2, the engine already has them bucketed by type.
You can also do: for (TActorIterator<ASomeActorType> ItActor = TActorIterator<ASomeActorType>(World); ItActor; ++ItActor)
or for (ASomeActorType* Actor : TActorRange<ASomeActorType>(World))
I’m not 100% sure if it has buckets per-world or not. It may iterate all actors and skip those not in the right world, but that’s only a perf problem in the Editor so can usually be ignored. Of course it also matters when/how often you’re planning on doing this iteration and now big the collection might get but overall it’s fast enough to not worry about it in general.
TObjectIterator works the same way (pre-bucketed). You have to do your own world filtering though when that’s relevant (like iterating any actor component type).
After reviewing the engine’s source code, it appears that if the template type is ‘AActor’, the first method will be used. Otherwise, the engine retrieves the object from the typed bucket. These buckets are not specific to each world, so the engine will iterate through all actors and skip those that are not in the correct world.