Lazy Switch | akatz-loops
A boolean switch that doesn't execute the losing branch
- on_false
- on_true
- *
LazySwitch | akatz-loops is an A/B switch with a superpower: it only computes the branch you actually select. A plain switch node routes whatever both upstream branches already produced - which means both branches had to run. This one declares its inputs lazy, and ComfyUI's execution model (yes, the same execution-inversion engine that powers the pack's loops) only evaluates the chosen input's upstream graph. The losing branch isn't just discarded, it's never executed at all.
That's a real difference. If one branch is an expensive sampler pass and the other is a cheap VAE decode, a lazy switch can skip the expensive work entirely when you pick the cheap path. It also means a branch that would crash (a model load that fails, a latent shape mismatch) won't kill the run as long as you don't select it.
Inputs and outputs
- switch (BOOLEAN) - the selector.
true→on_true,false→on_false. - on_true / on_false -
*inputs, both lazy. Any type. - output - a single
*with the winning value.
That's it. There's no first-non-null fallback logic here like rgthree's Any Switch (see the KB's node-plumbing writeup for that family); this is an explicit selector, which is the shape you want when you decide the path, not the graph.
When you'd use it
In a loop, a lazy switch is how you say "if this iteration's condition is true, do the expensive refinement; otherwise pass through unchanged." Wire the sampler branch into on_true, a passthrough into on_false, and the loop's counter or a comparison into switch. The lazy part matters because now the refinement branch only costs you when its condition actually fires - over N iterations that's the difference between running the sampler 10 times and running it twice.
Installing it
Part of the Akatz-Loop-Nodes pack (repo ComfyUI-Execution-Inversion):
cd ComfyUI/custom_nodes
git clone https://github.com/akatz-ai/ComfyUI-Execution-Inversion
# restart ComfyUI
Or ComfyUI Manager → "Akatz-Loop-Nodes". Only dependency is opencv-python; no model files.
Gotchas
Lazy evaluation only skips work it can prove it doesn't need. If the losing branch has side effects - a Save Image, a node that writes a file - those genuinely won't run, which is almost always what you want, but it surprises people who expected "route after execution." Also, if you bypass the winning branch's upstream (or leave switch unconnected), the node falls back to one input and can pass None; keep the boolean wired.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| switch | BOOLEAN | — | |
| on_false | * | — | |
| on_true | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| * | * | — |