Can Streamlit be used to write medium-large, complex apps?
Encouraged with the result of creating several small streamlit apps, I have taken a big step ahead:
I now have a streamlit program that currently stands at about 5.5K lines (and I am only about half way through). Some of the data entry screens contain 30+ widgets of different types.
Every time I try to update a field, it takes anywhere between 6-11 seconds (sometimes more) per field update / screen refresh. Consequently, the entire data entry process is slowed down considerably.
I canāt use st.forms as many widgets on a screen have different conditional logic attached to them. I have tried performance enhancements (eg. create lists with sql outside the data entry function, etc.), without much improvement.
I am unable to reproduce the code here due to confidentiality issues and code size.
Any suggestion will help. Is streamlit really the right choice for large, complex apps?
I think this is the answer to why you are having issues. If there are 30 different widgets than can be changed, and each one kicks off the a re-run, youād have to use a pretty hefty combination of caching and state to make this process run in a performant manner.
Iām a product manager at Streamlit and would love to see that massive app / hear more about what youāre doing. Weāre currently working on some performance improvements, so curious to see if weāre tackling the right problems. Would you be up for a 20-30 min call sometime this or next week?
I leave this code permanently in my app and wrap it with a feature toggle if.
In this way you can quickly run small benchmarks by just setting a bool to true and get a pretty good feeling about where your code is slow.
If you focus on the right parts of your code, you can even run large amounts of code quite quickly.
I also store my data in optimized dataframes stored in parquet files that can be read very quickly. This can even be quicker than caching the dataframe.
Another point is that you need caching but you should not overdo it and not use it for every function, especially for large dataframes.
For me it has worked out to use kind of a function chaining where each function calls the previous one and also gets some settings from userinput, usually as a dict. In this way you can use caching for some of them and only rerun the calculations that need to be rerun based on the new user input.
I also made some performance improvements on the aggrid component to better suit my application. Things like this can also be necessary if you find your bottleneck not to be in your own code.
Ah totally forgot: I also wrote a component (streamlit-profiler) a few weeks ago, which does the same benchmarking trick @thunderbug1 just posted (but itās a tiny bit easier to use and looks a bit more Streamlit-y ). Let me know if thatās useful!
@jrieke, Neat component!
For practical use it would be great if there were arguments to enable/disable the profiler and to activate the detailed output which was handy in a couple of situations
Iām currently facing the exact same problem. Iām pulling more than 1M records from Snowflake into pandas dataframe and filtering it using 10-12 widgets. I have tried out many suggestions that I found online, to improve the app performance, but thereās no luck. Itās still very slow and takes 10-15 seconds if any of the widget values is changed. Is there any solution to fix this problem?
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking āAccept allā, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.