AbdullahAlfaraj / AbdullahAlfaraj/Auto-Photoshop-StableDiffusion-Plugin

after comfyui 52aaee2 update,workflow loadimge became slower too much

未关闭
#503 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
7.3k
派生
527
PR 合并指标
30 天内没有已合并 PR

描述

**Comfyui 52aaee2 update on 2024.07.02 chaged something about image input.Before this version,realtime is fast,after this version realtime is not real.
the update is like this:**

_diff --git a/server.py b/server.py
index 30ea90c6c91c97a603af66b10419cfe65fa083bf..5b98620ad38010f3afb5bf70ab7d1df5242443f0 100644
--- a/server.py
+++ b/server.py
@@ -12,6 +12,7 @@ import json
import glob
import struct
import ssl
+import hashlib
from PIL import Image, ImageOps
from PIL.PngImagePlugin import PngInfo
from io import BytesIO
@@ -153,10 +154,24 @@ class PromptServer():
type_dir = folder_paths.get_output_directory()

return type_dir, dir_type
-
+
+ def compare_image_hash(filepath, image):
+ # function to compare hashes of two images to see if it already exists, fix to #3465
+ if os.path.exists(filepath):
+ a = hashlib.sha256()
+ b = hashlib.sha256()
+ with open(filepath, "rb") as f:
+ a.update(f.read())
+ b.update(image.file.read())
+ image.file.seek(0)
+ f.close()
+ return a.hexdigest() == b.hexdigest()
+ return False
+
def image_upload(post, image_save_function=None):
image = post.get("image")
overwrite = post.get("overwrite")
+ image_is_duplicate = False

image_upload_type = post.get("type")
upload_dir, image_upload_type = get_dir_by_type(image_upload_type)
@@ -183,15 +198,19 @@ class PromptServer():
else:
i = 1
while os.path.exists(filepath):
+ if compare_image_hash(filepath, image): #compare hash to prevent saving of duplicates with same name, fix for #3465
+ image_is_duplicate = True
+ break
filename = f"{split[0]} ({i}){split[1]}"
filepath = os.path.join(full_output_folder, filename)
i += 1

- if image_save_function is not None:
- image_save_function(image, post, filepath)
- else:
- with open(filepath, "wb") as f:
- f.write(image.file.read())
+ if not image_is_duplicate:
+ if image_save_function is not None:
+ image_save_function(image, post, filepath)
+ else:
+ with open(filepath, "wb") as f:
+ f.write(image.file.read())

return web.json_response({"name" : filename, "subfolder": subfolder, "type": image_upload_type})
else:_

**If I delete these codes in comfyui/server.py, everything will be faster.But every update will overwrite server.py.So,somebody could tell why this happen ?**

贡献指南

这个仓库没有索引到贡献指南

调研方向

该 issue 指向 ComfyUI 的 server.py 在 commit 52aaee2 之后出现的 performance regression,其中 image upload 因新的 hash 比较函数而变慢。先检查 server.py 中的 compare_image_hash 函数,重点关注它如何读取 image file 并计算 hash。查找不必要的文件读取或 seek 操作等低效点。分别在有和没有 hash 比较的情况下测试 image upload workflow,以确认变慢。目标是理解为什么 hash 比较很慢,并提出一个在不降低 performance 的情况下保持 duplicate detection 的 fix。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
backend, performance
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。