Flecs, and I imagine most archetype-based solutions rely on persistent queries, which means that you register a query with the world, and register archetypes with them as they are created. Therefore when you're iterating, you don't need to perform any searching: you just iterate contiguous arrays.