Lazy and right-to-left evaluation in the node tree As someone with a programming background, here's a fundamental thing about the Cycles node tree I've been thinking about. Let's say you have a node setup like this:



Here we have two computationally intensive shaders, called "Gigantic Shader A" and "Gigantic Shader B", and a Mix Shader is used to switch between them using some black-and-white mask.

In programming terms, this setup can be thought of as an if-else construct, with shader A and B being the two execution branches of the if-else construct.

Now, in basically every sane programming language, the two if-else branches are evaluated "lazily", meaning that either only the first branch or only the second branch is evaluated, depending on whether the if condition evaluates to true or false.

So here are my questions:

(1) Does Cycles have this lazy evaluation optimization as well? More specifically, is Cycles smart enough to figure out that if Fac=0 or Fac=1 in the above Mix Shader, it can completely ignore either shader B or shader A?

(2) If Cycles does have this optimization, then is it also true that the node tree is actually evaluated from right to left, starting at the Material Output node, and not from left to right, as one would naively assume? Because I can't think of any other way to implement lazy evaluation than going from right to left.
When executing shaders, a special optimization is applied to Mix Shader nodes. If Factor evaluates to 0 or 1, any nodes that are only reachable via the unused branch of the mix are not evaluated.

Taken from this page:

https://docs.blender.org/manual/en/dev/render/cycles/optimizations/nodes.html

This page also describes how the node tree is evaluated.