-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Run pre/post processing in threadpool #7327
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-builds.s3.amazonaws.com/8d851a6c2fea26aa6e08012d06c79abf817712f4/gradio-4.19.0-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@8d851a6c2fea26aa6e08012d06c79abf817712f4#subdirectory=client/python" |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
The real issue is that Gallery takes criminally long to postprocess 30 images, which is really not that many. I can't reproduce the 15-second wait, but it does take several seconds on my local computer. Can we do something to improve that? Otherwise, these changes look good. I tested with |
Thank you @abidlabs , that's so helpful you tested this with Lite. gradio/js/wasm/src/webworker/index.ts Lines 151 to 162 in 49d9c48
|
069f225
to
7b11ab3
Compare
@abidlabs I made two speed-ups to the gallery postprocess - 1) only doing one call to I stil lhink we should be running pre/postprocess in the threadpool because if for whatever reason we add a new component/custom component whose pre/postprocess takes more than a second the whole page will freeze which is not ideal. This should be good for another look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Beautiful speedup @freddyaboulton!
Thanks for the review! |
Description
Closes: #7241
In some cases, the component pre/postprocessing takes a long time (like big galleries or chatbots) and it can block the event loop. We can run the processing in the thread pool to avoid the block. Tested this with the following demo and running two concurrent users:
main - notice how the demo on the right will freeze until the first one finishes
postprocess_main_compressed.mov
pr - both finish at the same time
postprocess_pr_compressed.mov
🎯 PRs Should Target Issues
Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.
Not adhering to this guideline will result in the PR being closed.
Tests
PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests:
bash scripts/run_all_tests.sh
You may need to run the linters:
bash scripts/format_backend.sh
andbash scripts/format_frontend.sh