Nodes/ComfyUI-UniversalToolkit/Lazy Switch KJ (UTK)
ComfyUI Node

Lazy Switch KJ (UTK)

A switch that skips computing the branch you don't take

By whmc76·Created about a year ago·Updated 2 months ago· 72
Lazy Switch KJ (UTK)
  • on_false
  • on_true
  • output
switch

Plain switches in ComfyUI are dumb in a specific way: they pick one branch, but everything feeding both branches still runs. So a conditional "inpaint this face only if the mask found one" pays for the unused path anyway. Lazy Switch KJ (UTK) is the smarter version - it only evaluates the branch you actually use. That's the whole pitch, and for expensive branches it's a real performance win, not a gimmick.

What "lazy" means here

The node is a straight port of the KJNodes lazy switch pattern. It takes three inputs: a boolean switch, an on_true value, and an on_false value, and returns whichever you picked as output. Any data type works - images, masks, strings, latents, whatever - because the inputs are wildcard/ANY typed.

The lazy part lives in a check_lazy_status method. When ComfyUI executes, it asks the node "what do you actually need?" and the node answers based on the switch value: only the branch that's going to be returned. Every node upstream of the unused branch never runs. That's the difference between this and a conditional-connect node, and it's why you'd reach for it in a workflow where one branch is expensive - say, a full inpainting pass that should only fire when a mask passes a validity check.

The inputs that matter

  • switch - a boolean. Wire it to a real condition, like a Check Mask node's output, a math comparison, or an explicit boolean toggle. That's the brain.
  • on_true / on_false - the two candidates. Only the one matching the switch is computed.

That's it. One output, output, carrying whatever came through.

Installing it

It's in the ComfyUI-UniversalToolkit pack:

  • ComfyUI Manager → search ComfyUI-UniversalToolkit → Install → restart, or
  • cd ComfyUI/custom_nodes && git clone https://github.com/whmc76/ComfyUI-UniversalToolkit then pip install -r requirements.txt and restart.

Zero extra dependencies - it's just ComfyUI's own typing system.

Gotchas and honest caveats

  • Lazy evaluation depends on ComfyUI's executor respecting check_lazy_status. On modern ComfyUI it does. The code has a fallback path for older versions that degrades to a plain switch, so it never breaks - you just lose the optimization.
  • The savings are only real when the unused branch is expensive. Switching between two cheap string values saves you nothing and adds a node. Where it shines: gating a sampling pass, a ControlNet preprocessing branch, or a per-frame video process behind a condition.
  • Don't use it as a "safe" bypass for broken branches. If ComfyUI still validates the graph, an upstream node with a hard error can surface during scheduling even when its branch isn't selected. Lazy switching skips execution, not graph parsing.

For the classic "only run the expensive fix when the condition says so" workflow, this is the node. If you're already running Kijai's KJNodes you may not need it - the original lives there - but inside the UniversalToolkit pack it means you don't need to install a whole second pack just for one switch.

CategoryUniversalToolkit/Tools

Inputs (3)

NameTypeDefaultDescription
switchBOOLEANBoolean value to control which input is returned
on_false*Value returned when switch is False
on_true*Value returned when switch is True

Outputs (1)

NameTypeDescription
output*