-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Improve performance with large number of queued prompts #8176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Nice work looking into this with benchmarks to show. I had something similar opened months ago with zero activity but I'll go ahead and close that since I think your implementation makes more sense. |
This is great. Testing Network & UI Performance
With this PR:
Without this PR:
I can do some other tests later with more features that interact with the prompt queue. |
Testing Queue Operations/Features from UI
test-queue-pr-queue-button-features.mp4Everything seems to work the same as before, with better performance in the case where we queue a large batch at once. |
|
This PR comfyanonymous/ComfyUI#8176 in the ComfyUI repository broke Visionatrix, specifically the dev version. These small changes are similar to parts of that PR - they fix it. Signed-off-by: bigcat88 <[email protected]>
Mitigates Comfy-Org/ComfyUI_frontend#2435
ComfyUI's web app exhibits significant lag when a large number of prompts are queued. I verified what was found in the linked thread, pinpointing the slowdown to the specific call
api.getQueue()
as the number of prompts grows. Every time a prompt is submitted, the front-end synchronizes the entire queue state by making this call.Profiling the back-end, I found most of the time is spent executing
copy.deepcopy
inside PromptQueue while a mutex is held.This PR adds a new version of PromptQueue's
get_current_queue
method that performscopy.copy
instead ofcopy.deepcopy
. Allowing read-only shared access is safe as long asPromptQueue
treats its queue items as immutable, which it does by returning deep copies in its other methods. I named the new versionget_current_queue_volatile
to remind callers they must only read and release these values.Using the updated method allows Comfy to respond much faster to requests to the
/queue
route. The web app remains usable on my machine with several hundred queue items. I enqueued 300 prompts for these benchmarks.Notice how the whole

deepcopy
block is gone, and you can actually see Comfy working on other stuff:Caching the JSON representations may be another 80/20 fix. I could look into that in the future. A more complex but optimized solution would be to rewrite state sync so the front end only requests a diff with updates to the queue instead of a full sync. Still, this quick fix helps a lot.