Hi, I have created the following application for streamlit and I think I am losing a lot of performance because of the cache. When I run one of the pages in visual studio, I get this in the console repeatedly
If you go into the application, you can see how it is too long in running time. I have measured the code execution time in python and it is quite low.
If you’re experiencing performance issues with your Streamlit application, particularly related to the caching mechanism, here are a few suggestions to improve the performance:
Optimize your code: Analyze your code to identify any potential bottlenecks or areas that can be optimized. Look for inefficient loops, redundant calculations, or unnecessary data manipulation. By improving the efficiency of your code, you can reduce the overall execution time.
Granular caching: Check if you’re caching the entire page or function when only specific parts need to be cached. Streamlit’s caching mechanisms, such as @st.cache decorator, allow you to cache specific functions or sections of code. By narrowing down the scope of what you cache, you can avoid unnecessary recalculations and improve performance.
Use memoization techniques: Streamlit’s caching mechanism is based on memoization. However, in some cases, you might benefit from implementing your own memoization technique tailored to your specific use case. This allows you to have more fine-grained control over the caching process and optimize it according to your needs.
Leverage background processes: If your Streamlit app involves long-running tasks or computations, consider offloading those tasks to background processes or worker threads. This can prevent the UI from becoming unresponsive and enhance overall performance. You can use Python libraries like multiprocessing or concurrent.futures to achieve parallel or asynchronous execution.
Profile your code: Use profiling tools, such as Python’s cProfile module, to identify the exact areas of your code that are taking the most time to execute. This will help you pinpoint performance bottlenecks and focus your optimization efforts where they will have the most impact.
Consider asynchronous programming: If your Streamlit app involves making multiple external API calls or performing I/O operations, consider using asynchronous programming techniques. Libraries like asyncio or aiohttp allow you to perform multiple tasks concurrently, improving overall performance by minimizing waiting times.
By following these suggestions, you can identify and address performance bottlenecks in your Streamlit application. Remember to profile your code to target specific areas for optimization and test the performance improvements iteratively.
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.