Kanaries/pygwalker

[BUG] Memory growth when using PyGWalker with Streamlit

Open

#618 ouverte le 13 sept. 2024

Voir sur GitHub
 (3 commentaires) (0 réactions) (1 assigné)Python (405 forks)batch import
P1buggood first issue

Métriques du dépôt

Stars
 (8 606 stars)
Métriques de merge PR
 (Merge moyen 17h 40m) (5 PRs mergées en 30 j)

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

On this screenshot a debug app memory profiling is displayed. Debug app memory profile

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!

Guide contributeur