From 4b2b24906a288e82c28dc0fe9b1b1d30ccbeefc5 Mon Sep 17 00:00:00 2001 From: meimeilook <meimeilook@hotmail.com> Date: Sat, 15 Mar 2025 14:08:57 +0800 Subject: [PATCH] Put node_info caching in memory,and now 30x speedup when loading the page. --- server.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server.py b/server.py index 19568622..a3d4b94a 100644 --- a/server.py +++ b/server.py @@ -21,6 +21,7 @@ from io import BytesIO import aiohttp from aiohttp import web import logging +from functools import lru_cache import mimetypes from comfy.cli_args import args @@ -552,6 +553,7 @@ class PromptServer(): async def get_prompt(request): return web.json_response(self.get_queue_info()) # use getattr speedup 2x times in load node info + @lru_cache(maxsize=None) def node_info(node_class): obj_class = nodes.NODE_CLASS_MAPPINGS[node_class] input_types = obj_class.INPUT_TYPES() @@ -587,6 +589,11 @@ class PromptServer(): except Exception: logging.error(f"[ERROR] An error occurred while retrieving information for the '{x}' node.") logging.error(traceback.format_exc()) + + # Debug node_info in the current memory cache + #cache_stats = node_info.cache_info() + #print(f"node_info Cache Hits: {cache_stats.hits}, Misses: {cache_stats.misses}, Current Memory Cache Size: {cache_stats.currsize}") + response = web.json_response(out) response.enable_compression() return response