Calling TraceRay inside an if statement of a Hit shader

Hi everyone, I am writing a ray tracer to learn how everything works basically and I am trying to optimise some aspects of the rendering, one of them is Tracing recursive rays for shadows only when necesary (for example skip that step if an object is outside of the spotlight cone).

To achieve that I put an if statement comparing in this case the cutout of the cone and put the function inside but from what I see the TraceRay function is still being executed (tried with a constant to test in case it would never be true).

My question is: since the function is still being called is it worth it to put that condition or is it better to just let it brute force its way? And is there a more correct way of tackling this aspect?

I haven’t worked much in raytracing and normally I try to prevent myself from using conditions in shaders but I can’t think of another good way of working it out. Thank you in advance for any response!