How do I hide all nodes out of a certain distance with the least delay?

Hello all,
So my question for today is how can I hide all nodes out of “render distance”? I have hundreds if not thousands of nodes in a NodePath, and I need to iterate over them and decide which ones to hide based off of the distance to the player.

Currently I have it set up as this:

for node in self.blockRenderNode.getChildren():
                # get all nodes within render distance
                if node.getDistance(self.camera) <= Worldvars.renderDist:
                    node.show()
                else:
                    # hide nodes out of render distance
                    node.hide()

is there any way I can do this faster? I need this to be running parrallel to several game logic functions, and it needs to complete in less than 40 ms if possible. I am open to restructuring the way I have everything organized, but keep in mind that as the game is continued more and more nodes will be added to the game, so it needs to be fast even with 50k+ NodePaths.

Thanks in advance!

May I ask why you’re trying to do this? Panda3D already hides everything outside of render distance for you.

It is for a game. what is that about a panda3d render distance? Is that some default thing I didn’t know about?

Panda3D’s lens has a “far” distance. Everything beyond this distance will be culled by Panda3D automatically. This happens more efficiently than doing what you suggest.

https://docs.panda3d.org/1.10/python/programming/camera-control/perspective-lenses

You can help Panda’s hierarchical culling algorithm by structuring your scene graph hierarchically, using nodes to contain groups of objects that are close to each other. Then, Panda can cull away the entire group easily if that is out of view (such as beyond that distance), rather than having to check every object individually whether it is out of view.

thank you! that solves the exact problem I had.