Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Execute async node earlier (#8865)

JettHu7bc7dd2aa203
diff --git a/comfy_execution/graph.py b/comfy_execution/graph.py
index c79243e1e..60e2ab91e 100644
--- a/comfy_execution/graph.py
+++ b/comfy_execution/graph.py
@@ -3,6 +3,7 @@ from typing import Type, Literal
import nodes
import asyncio
+import inspect
from comfy_execution.graph_utils import is_link
from comfy.comfy_types.node_typing import ComfyNodeABC, InputTypeDict, InputTypeOptions
@@ -239,8 +240,15 @@ class ExecutionList(TopologicalSort):
return True
return False
+ # If an available node is async, do that first.
+ # This will execute the asynchronous function earlier, reducing the overall time.
+ def is_async(node_id):
+ class_type = self.dynprompt.get_node(node_id)["class_type"]
+ class_def = nodes.NODE_CLASS_MAPPINGS[class_type]
+ return inspect.iscoroutinefunction(getattr(class_def, class_def.FUNCTION))
+
for node_id in node_list:
- if is_output(node_id):
+ if is_output(node_id) or is_async(node_id):
return node_id
#This should handle the VAEDecode -> preview case