Skip to content

Commit 7bc7dd2

Browse files
authored
Execute async node earlier (Comfy-Org#8865)
1 parent 938d3e8 commit 7bc7dd2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

comfy_execution/graph.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import nodes
55
import asyncio
6+
import inspect
67
from comfy_execution.graph_utils import is_link
78
from comfy.comfy_types.node_typing import ComfyNodeABC, InputTypeDict, InputTypeOptions
89

@@ -239,8 +240,15 @@ def is_output(node_id):
239240
return True
240241
return False
241242

243+
# If an available node is async, do that first.
244+
# This will execute the asynchronous function earlier, reducing the overall time.
245+
def is_async(node_id):
246+
class_type = self.dynprompt.get_node(node_id)["class_type"]
247+
class_def = nodes.NODE_CLASS_MAPPINGS[class_type]
248+
return inspect.iscoroutinefunction(getattr(class_def, class_def.FUNCTION))
249+
242250
for node_id in node_list:
243-
if is_output(node_id):
251+
if is_output(node_id) or is_async(node_id):
244252
return node_id
245253

246254
#This should handle the VAEDecode -> preview case

0 commit comments

Comments
 (0)