Skip to main content

Overview

ComfyUI’s execution system is a sophisticated asynchronous engine that manages workflow execution, node processing, caching, and resource management. It handles everything from input validation to output delivery with support for interrupts, dynamic graphs, and efficient memory usage.

Execution Pipeline

The execution pipeline consists of several key stages:
1

Prompt Validation

Validate workflow structure and inputs using validate_prompt()
2

Queue Addition

Add validated prompts to the execution queue with priority
3

Cache Initialization

Set up caching system and check for cached results
4

Node Execution

Execute nodes in dependency order with async support
5

Result Collection

Gather outputs and send to client

Prompt Executor

The PromptExecutor class orchestrates workflow execution:

Execution Loop

From execution.py:730-750:

Execution Results

Three possible execution results:

Cache System

Cache Types

ComfyUI supports multiple caching strategies:

CacheSet Implementation

From execution.py:109-143:
Two-Level Caching: The system maintains separate caches for outputs (based on inputs) and objects (based on node ID) for optimal performance.

Cache Entry Structure

IS_CHANGED Cache

Tracks whether node inputs have changed:

Node Execution Function

The core execute() function handles individual node execution:

Lazy Evaluation

From execution.py:486-499:
Lazy Loading: Nodes with check_lazy_status can defer loading inputs until actually needed, saving memory and computation.

Async Task Handling

From execution.py:532-540:

Execution Queue

The PromptQueue manages pending executions:

Task Completion

Interrupt Handling

Executions can be interrupted gracefully:
From execution.py:593-601, interrupts are handled specially:
When interrupted:

Error Handling

Exception Processing

From execution.py:602-631:
OOM Handling: Out-of-memory errors trigger automatic model unloading to free VRAM.

Progress Tracking

The execution system tracks and reports progress:

Message Broadcasting

Events are broadcast to clients:

Event Types

execution_start

Execution begins

execution_cached

Cached nodes identified

executing

Node started execution

executed

Node completed with output

execution_error

Error occurred during execution

execution_interrupted

User interrupted execution

execution_success

Workflow completed successfully

Performance Optimization

Choose the right cache type for your use case:
  • Classic: Fast but uses more memory
  • LRU: Bounded memory usage
  • RAM Pressure: Adaptive based on available RAM
  • None: Minimal memory for large batches
Use async nodes for:
  • Network requests
  • File I/O operations
  • Long-running computations
  • Parallel processing
Implement check_lazy_status to:
  • Defer expensive inputs
  • Save memory on unused branches
  • Enable conditional execution
Use INPUT_IS_LIST and OUTPUT_IS_LIST for:
  • Processing multiple images
  • Aggregating results
  • Parallel GPU operations

See Also

Workflows

Workflow structure and format

Nodes

Node system and implementation

Models

Model loading and caching