pythongosssss / ComfyUI-Custom-Scripts

Enhancements & experiments for ComfyUI, mostly focusing on UI features
MIT License
1.86k stars 144 forks source link

[Bug] Lora Loader is causing massive slowdown / delays #357

Open CloudWalker-II opened 1 month ago

CloudWalker-II commented 1 month ago

The pysssss LoraLoader is causing significant delays / slowdowns in when generating images.

I've tried with a clean install of ComfyUI with only pysssss Custom Script installed, no other custom nodes, and it's clear that it's the Lora Loader causing these delays.

Every time I queue a prompt with pysss Lora Loader active in the workflow the console prints "got prompt", then it does nothing for several seconds (~7 seconds) and then when the generation starts up after that, it self is also slower.

Generating 4, 512x512 images with the default ComfyUI Lora Loader node takes 4,97s (~1.2s / image) for me. Then using the exact same seeds, settings, checkpoint and Lora but with the pysss Lora node instead, the same images takes a total of 33,47s (~8,3s / image) to generate.

This delay / hang up is there for both SD and SDXL, changing checkpoint or loras doesn't seem to have an effect either. I've also had this issue on both a manual git-pull install of ComfyUI as well as for the stand alone version.

Needles to say this renders the Lora Loader node unusable which is such a shame because no other alternative holds up in my opinion.

I'm on Windows 11 working with the latest ComfyUI versions. Prior to this I've used the Lora loader without any problems. ComfyUI: v0.2.2-72-g3a0eeee ComfyUI frontend: v1.2.60 Python: 3.11.9 (tags/v3.11.9:de54cf5, Apr 2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)] Pytorch: 2.4.1+cu124

Thank you for all the work, hopefully you'll have time to look into this issue.

CloudWalker-II commented 1 month ago

Some further testing of this issue: It doesn't seem to be related to the new frontend I ran comfy with --front-end-version Comfy-Org/ComfyUI_legacy_frontend@latest and the issue still persisted.

It does seem to be connected to how many Loras and/or folders, after moving a large amount of Loras outside the search path, the delay time got reduced by a decent amount, however the delay is still noticeable and problematic.

Maybe I just wasn't fully aware of the delay in the past but it certainly feels like this has not been an issue in the past, despite a large amount of Loras, Hopefully there is some possibilities for optimizations, or there might still be some other issue causing significant delays, it's hard to say. I really hope something can be done about this tough since I find the functionality this node brings extremely helpful.

NeedsMoar commented 1 month ago

It's related to comfy's new workflow execution system which goes forward instead of recursively from the back. To do this it needs to know which nodes haven't changed more clearly and queries them. It seems to force an update on these which re-scans and regenerates the entire directory list for each node. Comfy's LoRA Loader doesn't have this problem because it uses a global cache of the files of each type that's only generated once unless the interface is completely refreshed.

CloudWalker-II commented 1 month ago

@NeedsMoar Thank you for that extra insight in the issue. It'll be helpful if I decide to revert back to an earlier comfy build to avoid this issue.