Nodes/KJNodes for ComfyUI/Lazy Switch KJ
ComfyUI Node Runs on cloud

Lazy Switch KJ

A switch that actually skips the branch it doesn't pick

By kijai·Created 3 years ago·Updated about 24 hours ago· 2,930
Lazy Switch KJ
  • on_false
  • on_true
  • *
switch

The word "lazy" is the whole point here, and it's a good thing. Most switch nodes in ComfyUI are a lie of convenience: they take two inputs, hand you one, and quietly run both upstream chains anyway before throwing one away. So if one branch is an expensive upscale or a second model load, you paid for it even though you never used the output. LazySwitchKJ doesn't do that. It only evaluates the branch it selects. The other one - and everything feeding into it - never executes.

That's why this node punches above its weight, and it's why it's one of the most-clicked nodes in the whole pack.

How it works

ComfyUI supports "lazy" inputs - inputs the engine only computes when a node actually asks for them. Most switch nodes don't use that mechanism, so they eagerly resolve everything wired in. This one marks its branch inputs as lazy, so the graph walker only travels up the path you chose. Set the switch to true and the entire on_false subgraph is dead weight that never runs. Flip it and the reverse.

Put a heavy branch behind it and you've got a real on/off toggle for whole sections of a workflow, not just an output selector.

The three inputs

That's all there is:

  • switch - a boolean. true sends on_true through, false sends on_false.
  • on_true / on_false - the two branches. Both are wildcard (*) type, so this passes anything: an image, a latent, a model, a conditioning, a string. Whatever you plug in, the same type comes out.

The single output is also * - it just carries whichever branch won.

Where you'd reach for it

The classic use is skipping an expensive optional stage. Say your workflow has an optional 4x upscale-and-refine pass at the end. Wire the base result to on_false, the upscaled result to on_true, and now a single boolean decides whether you burn the GPU time. When it's off, the upscaler genuinely doesn't run - this is the difference that saves you minutes per generation. You can also drive the boolean from another node to build conditional logic into a graph.

This is the same family of thinking as the quality-of-life packs everyone runs alongside ComfyUI Manager: it generates nothing, it just makes a big workflow behave. The lazy evaluation is what makes it more than cosmetic.

Installing KJNodes

ComfyUI Manager: open the Custom Nodes Manager, search "KJNodes for ComfyUI", install, restart. By hand: cd ComfyUI/custom_nodes && git clone https://github.com/kijai/ComfyUI-KJNodes, then pip install -r ComfyUI-KJNodes/requirements.txt (portable install: python_embeded\python.exe -m pip install -r ComfyUI\custom_nodes\ComfyUI-KJNodes\requirements.txt), then restart ComfyUI. No models, no heavy dependencies - the pack is built to stay light.

Gotchas

The main thing that surprises people: because the unused branch never executes, nodes on that side won't show progress, won't cache, and won't error even if they're misconfigured. That's by design. If you're debugging and expecting a node upstream of the losing branch to run, it won't - flip the switch to force it.

Also, since the inputs are wildcards, ComfyUI can't type-check them for you. Make sure both branches carry the same type of thing; if one side is an IMAGE and the other a LATENT, whatever consumes the output is going to complain the moment you flip the switch to the wrong one.

CategoryKJNodes/misc

Inputs (3)

NameTypeDefaultDescription
switchBOOLEAN
on_false*
on_true*

Outputs (1)

NameTypeDescription
**