Performance Problems with many small dataframes

I have an streamlit app that I use as a labeling tool.
The user gets a list of many small dataframes with a checkbox each and a submit button at the end of the form to submit the labels.

When I use st.write to write the dataframes to the browser, the browser has serious performance issues (100% cpu usage on one core that does not go away). The server side script has no performance problems.

When I use the AgGrid Component instead of st.write to write the dataframes, then I don’t see this issue.
Just wanted to let you guys know about this.

Hi @thunderbug1 -

Do you have a code example that demonstrates this?

Best,
Randy

sadly not yet, I tried to make a demo for this but for a tiny app it always works.
I do have some pretty big dataframes and figures in my big app (close to the maximum size), possibly this creates some kind of timing issue somewhere.
I will try again to create an example tomorrow.

1 Like

I was able to build a small example now. Apparently the streamlit dataframe causes a high cpu load when the checkboxes are clicked, probably due to layout changes and redraws which the Agrid component does not suffer from.

import streamlit as st
st.set_page_config(layout="wide")
import pandas as pd

from st_aggrid import AgGrid, GridOptionsBuilder

s = pd.Series(list('abcganlwnfneowb'))
df = pd.get_dummies(s)

with st.form("test"):
    for i in range(30):
        st.checkbox(label="test", key=i)

        st.write(df) 
        #gb = GridOptionsBuilder.from_dataframe(df)
        #AgGrid(df, gridOptions=gb.build(), key=f"grid{i}")

    if st.form_submit_button("submit"):
        st.info("submitted")