-
Notifications
You must be signed in to change notification settings - Fork 714
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
[BUG] Memory growth when using PyGWalker with Streamlit #618
Comments
Hi @ChrnyaevEK , Thanks for your feedback. Using pygwalker latest version, and try to cache StreamlitRenderer, it may avoid memory growth. from pygwalker.api.streamlit import StreamlitRenderer
import pandas as pd
import streamlit as st
@st.cache_resource
def get_pyg_renderer() -> "StreamlitRenderer":
df = pd.read_csv("xxx")
return StreamlitRenderer(df)
renderer = get_pyg_renderer()
renderer.explorer() There are several reasons why pygwalker memory grows:
In the next period of time, pygwalker will optimize the user experience of the streamlit component. Thank you again for your feedback. |
Hi @longxiaofei ! Thanks for your attention. CachingI'm afraid that caching is not an option in this case, our data change with every request and thus cached function should look more like this:
which basically is equivalent for no cache at all. I did however test this approach and I'm still facing the same strange behavior.
Running this app locally (windows, as described in first massage with pygwalker 0.4.9.3 as this is our production version) results in constantly growing memory (it seems to occasionally release insignificant amount of memory, but it does not return to initial values). Other local testsI did also test few other code snippets locally to confirm that memory will eventually be released, but it seems like it's not. Bare StreamlitCode
Debug sequence
GraphSee attached PDF Streamlit with PyGWalkerCode
Debug sequence
GraphSee attached PDF Conclusions up to the momentApps with and without PyGWalker both hold memory. PyGWalker allocate memory on every rerun, bare Streamlit seems to eventually saturate (may not allocate noticeable amount of memory). There is no issue openning multiple Streamlit apps without PyGWalker, but as soon as PyGWalker is used we run out of memory (even with cache). This seems to be confirmed locally and on Azure. I still suspect some issue with PyGWalker on Streamlit (may be PyGWalker just misuse Streamlit caching mechanisms), can you please check steady memory growth when running minimal PyGWalker app locally? Thanks! |
Describe the bug
I observe RAM growth when using PyGWalker with Streamlit framework. The RAM usage constantly grow on page reload (on every app run). When using Streamlit without PyGWalker, RAM usage remain constant (flat, does not grow). It seems like memory is never released, this was observed indirectly (we tracked growth locally, see reproduction below, but we also observe same issue in Azure web app and RAM usage never decline).
To Reproduce
We tracked down the issue with isolated Streamlit app with PyGwalker and memory profile (run with
python -m streamlit run app.py
):Observed output for a few consequent reloads from browser (press
R
, rerun):Expected behavior
RAM usage to remain at constant level between app reruns.
Screenshots
On screenshot you may observe a user activity peaks (cause CPU usage) and growing RAM usage (memory set).
On this screenshot a debug app memory profiling is displayed.
Versions
streamlit 1.38.0
pygwalker 0.4.9.3
memory_profiler (latest)
python 3.9.10
browser: chrome 128.0.6613.138 (Official Build) (64-bit)
Tested locally on Windows 11
Thanks for support!
The text was updated successfully, but these errors were encountered: