Uncalculated light path node adding to render time when outside of group

I notice that when a node is outside of a group that it significantly increases render time, even if the logic inside of the group stops it being processed.

for example I have a light path node plugged into a group, inside the group it leads to another group which has a mix node to decide if the light path’s branch will be used based on a fac slider.

I notice if the fac is set to 0, bypassing the branch that leads to the light path node, that the render time is around 30% longer than if I put the light path node inside of the nested group (where it still isn’t called).

The problem is that if I have multiple branches that use the same light path output, then when more than one of them is in use I get a considerable performance increase from having one light path node outside of the groups, rather than having a light path node inside each group. I’m not sure why, as I believe cycles de-duplicates nodes at render time, and also loses the concept of groups.

Can anyone explain the reason for this? I’ve worked around it by having an additional mix node outside of the group to cancel the light path node before it even hits the outer group, but I’d be interested to understand the cause, so I might be able to optimise further.

Please show an example node setup when asking questions like this. It’s difficult to parse a text description, and there’s a reasonable chance the effect you are seeing happens due to a more specific setup than you describe.

The cost of executing a light path node itself is normally negligible, it’s how it disables or enables other nodes that has the performance impact.

Wierd, even if it’s not enabling other nodes, it’s still adding considerably to the render time. I’ll try and make an example.

Ray depth seems to be worse than diffuse ray/ shadow ray.

hmm, cant reproduce in a different file. Weird, I must be missing something somewhere in the tree. I’ll have to investigate further.

I did run into a bug the other night that left me scratching my head for several hours, when eventually copying the material to a duplicate object resolved the problem I was having. Possibly related.