# Fast selection of visible child components

I'm working on gui and I have next realization of base UI component:

So when I want to get absolute component position I need to sum all parent positions with component position.
Also if I want to skip rendering of component, in case if it out of bounds in one of parent components, I need to go through all parents and check this.
This approach is not very fast in case if there are too much components (about 10.000) so my ups decreased from 2600 to 400 updates per second.

Also till rendering I need to calculate scissoring rectangle by intersecting all parent rectangles with current rectangle.
IMO it is also little bit heavy operation in case a big tree of components.

Is there any way to increase it?
Or some fast way to select only visible components without checking every component in list?
Maybe there should be some another component structure?

• How hierarchical is this thing? Do you have a parent with a boatload of children? Typically your hierarchy can serve as your accelerator because you don't have to descend down into children if your parent's bounding rectangle isn't in view, e.g. Instead of working from child-up the tree, instead you can do a pass to gather the root(s) at the top of the hierarchy and descend downwards. Basically just do a linear pass first looking for components with a null parent. Those are your roots. Now work down from the roots and don't process a branch if its bounding box is not in view. – user77245 Dec 11 '17 at 15:16
• That said, if you want to make this structure more efficient, you'll likely end up making it cheaper if you make it a singly-linked list. Instead of a parent storing a child list, just store a pointer to the next sibling. So childList gets replaced by like nextSibling, a pointer which is null when you're at the end of the list. That'll make it so you don't have to allocate memory dynamically with every single component that has children. – user77245 Dec 11 '17 at 15:21