Let's say a game use a component-based hierarchy to store all of its entities. So it can have objects, characters, lights organized in some kind of tree.
When rendering the game, it needs to first render objects, then lights. So it needs to first traverse the hierarchy and render all the objects it finds, then traverse a second time to render all the lights it finds. What is a better way to do this? If the hierarchy has thousands of entities, it could be slow to traverse twice the tree.
I thought about having two lists, one containing objects to render, the second one being lights. Each time the user adds an entity to the hierarchy, it adds it to the corresponding list. This way, the game only have to traverse the object list then the light list, without traversing useless entities.
What is the best option?