Caching Mask to not Waste
Stop recomputing the same mask every run
- original_image
- executor
- original_image
- cached_mask
Masks are the quiet time-sink of any serious inpainting workflow. The author of the Caching to not Waste pack describes a workflow with twenty-odd Segment Anything mask creators - ground dino, SAM, all of it - and every single run recomputed every mask for the same photo. caching_mask exists to make that a one-time cost. Give it your source image and your mask-producing chain, and the mask gets saved to disk, keyed on the image. Every later run loads the file instead of re-segmenting.
It slots into the pack's core idea, which is worth stating plainly: cache the result, skip the whole upstream chain. Because the executor input is lazy-evaluated, a cache hit doesn't just save you the SAM forward pass - ComfyUI never even loads the SAM/dino models that feed the node. On a card that's constantly out of memory, that's the difference between a workflow that runs and one that dies at 80% with a "OUT OF MEMORY" alert.
How it works
Same recipe as the pack's other caching nodes: hash the source image's pixels plus your identification string, write the executor's mask to a PNG in ComfyUI/output/caching_to_not_waste, and return it on every future run.
The one thing that's unique to this node is the channel dropdown (red / green / blue / alpha). When the cached PNG is read back it's converted to RGB and the selected channel becomes your mask. Here's the honest version: for a normal single-channel mask, the saved image has the same value in all three color channels, so whichever channel you pick you get the same mask. Don't overthink it - leave it on red. It's there for the unusual case where a cached file genuinely carries different data per channel.
The inputs that matter
original_image- the source image that defines the cache. New pixels, new cache.executor- a MASK input. Your SAM/segment-anything chain, your thresholded color mask, whatever produces the mask.identification- the one that bites. Default is"mask". If you cache two different masks (say, subject and background) without renaming this, the second overwrites the first and both nodes silently return the same mask. This is the pack's single most common failure mode.force_recreate- true to regenerate once, then flip back.channel- as above; red by default.
Outputs: original_image (passthrough) and cached_mask (MASK), which wires into Set Mask / mask-to-conditioning, or directly into your inpaint setup.
Installing it
Manager → search Caching to not Waste, or:
cd ComfyUI/custom_nodes
git clone https://github.com/alastor-666-1933/caching_to_not_waste
Restart. No pip dependencies, no model downloads. Cache lives in ComfyUI/output/caching_to_not_waste; delete the folder to nuke everything.
Where people get burned
Beyond the identification trap: masks are stored as 8-bit PNGs, so a soft feathered mask loses its fractional precision. Fine for hard subject/background cuts, mildly lossy for gradient softness - if you're caching an anti-aliased mask for a face inpaint and seeing hard edges you didn't ask for, that's the quantization talking, not you. And as always, if you change the segmentation model or settings, flip force_recreate on once to bust the stale entry.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| identification | STRING | mask | — |
| channel | COMBO | 4 options: red, green, blue, alpha | |
| original_image | IMAGE | — | |
| executor | MASK | — | |
| force_recreate | BOOLEAN | false | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| original_image | IMAGE | — |
| cached_mask | MASK | — |