Kanaries / Kanaries/pygwalker

[BUG] Memory growth when using PyGWalker with Streamlit

Open
#618 3 comments 0 reactions 1 assignee Claimed by @longxiaofei View on GitHub
bug good first issue P1
Dominant language
Python
Stars
16k
Forks
889
PR merge metrics
No merged PRs in 30d

Description

**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`):

```
# app.py
import numpy as np
np.random.seed(seed=1)
import pandas as pd
from memory_profiler import profile
from pygwalker.api.streamlit import StreamlitRenderer

@profile
def app():
# Create random dataframe
df = pd.DataFrame(np.random.randint(0, 100, size=(100, 4)), columns=list("ABCD"))
render = StreamlitRenderer(df)
render.explorer()
app()
```
Observed output for a few consequent reloads from browser (press `R`, rerun):
```
Line # Mem usage Increment Occurrences Line Contents
13 302.6 MiB 23.3 MiB 1 render.explorer()
13 315.4 MiB 23.3 MiB 1 render.explorer()
13 325.8 MiB 23.3 MiB 1 render.explorer()
```
**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).
![Metrics from Azure](https://github.com/user-attachments/assets/d16d227c-2135-4bcc-b603-1ccb7147a342)

On this screenshot a debug app memory profiling is displayed.
![Debug app memory profile](https://github.com/user-attachments/assets/f1a0451e-45f4-45d7-b609-3f080ac6f921)

**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!*

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.