Kanaries/pygwalker

[BUG] Memory growth when using PyGWalker with Streamlit

Open

#618 创建于 2024年9月13日

在 GitHub 查看
 (3 评论) (0 反应) (1 负责人)Python (405 fork)batch import
P1buggood first issue

仓库指标

Star
 (8,606 star)
PR 合并指标
 (平均合并 17小时 40分钟) (30 天内合并 5 个 PR)

描述

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!

贡献者指南