Skip to content
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

Lazy load interactive or static variants of a component individually, rather than loading both variants regardless. This change will improve performance for many applications. #5215

Merged
merged 16 commits into from Aug 15, 2023

Conversation

pngwn
Copy link
Member

@pngwn pngwn commented Aug 14, 2023

Description

Lazy load only the interactive or static variant of a component as required rather than loading both. This needs a follow up or two but works well.

Closes: #3360

🎯 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

  1. 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

  2. You may need to run the linters: bash scripts/format_backend.sh and bash scripts/format_frontend.sh

@pngwn pngwn added the v: patch A change that requires a patch release label Aug 14, 2023
@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Aug 14, 2023

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
Visual tests all good! Build review
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/5028cf9dd453c7d5ce34fd396f79b4f3051d406c/gradio-3.40.1-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@5028cf9dd453c7d5ce34fd396f79b4f3051d406c#subdirectory=client/python"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Aug 14, 2023

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/accordion patch
@gradio/annotatedimage patch
@gradio/app patch
@gradio/audio patch
@gradio/box patch
@gradio/chatbot patch
@gradio/checkbox patch
@gradio/checkboxgroup patch
@gradio/code patch
@gradio/colorpicker patch
@gradio/dataframe patch
@gradio/dropdown patch
@gradio/file patch
@gradio/gallery patch
@gradio/highlightedtext patch
@gradio/html patch
@gradio/image patch
@gradio/json patch
@gradio/label patch
@gradio/markdown patch
@gradio/model3d patch
@gradio/number patch
@gradio/plot patch
@gradio/radio patch
@gradio/slider patch
@gradio/statustracker patch
@gradio/timeseries patch
@gradio/video patch
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Lazy load interactive or static variants of a component individually, rather than loading both variants regardless. This change will improve performance for many applications.

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@pngwn
Copy link
Member Author

pngwn commented Aug 14, 2023

Dno whats going on with the guides, will revert those changes before merging.

@abidlabs
Copy link
Member

In the sync you mentioned that this PR still needs some fixes to handle update(interactive=) -- let us know when that's ready, happy to review

@pngwn
Copy link
Member Author

pngwn commented Aug 14, 2023

@abidlabs READY FOR REVIEW!!!

@dawoodkhan82
Copy link
Collaborator

@pngwn Don't think updating interactive=False is working properly. I tried modifying hello_blocks for example:

import gradio as gr

def greet(name):
    return "Hello " + name + "!", gr.Textbox.update("sorry", interactive=False)

with gr.Blocks() as demo:
    name = gr.Textbox(label="Name")
    output = gr.Textbox(label="Output Box")
    greet_btn = gr.Button("Greet")
    greet_btn.click(fn=greet, inputs=[name], outputs=[output, name], api_name="greet")

if __name__ == "__main__":
    demo.launch()

@pngwn
Copy link
Member Author

pngwn commented Aug 14, 2023

I'll take a look!

@aliabid94
Copy link
Collaborator

Don't think updating interactive=False is working properly

I think this is because now we're loading the appropriate interactive/static version once at load time, right?

One issue I noticed is that even as an output component, the dataframe component still allows for editing the component. Seems like this issue was introduced before this PR though.

Otherwise looks great!

@pngwn
Copy link
Member Author

pngwn commented Aug 14, 2023

I think this is because now we're loading the appropriate interactive/static version once at load time, right?

I added some logic to load new components (if necessary when interactive changes), it just wasn't working all of the time, cos i messed up the order.

@dawoodkhan82 it should work now, if you can retest.

@aliabid94 I think i broke the dataframe in my refactor. Fixed that here as well.

Copy link
Collaborator

@aliabid94 aliabid94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me!

@dawoodkhan82
Copy link
Collaborator

@pngwn tested and it works great now!

@dawoodkhan82 dawoodkhan82 self-requested a review August 15, 2023 18:05
@pngwn pngwn merged commit fbdad78 into main Aug 15, 2023
13 checks passed
@pngwn pngwn deleted the 3360-lazyload-comps branch August 15, 2023 18:21
@pngwn pngwn mentioned this pull request Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v: patch A change that requires a patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clean up component folder structure + move components out of the app package
5 participants