Streamlit Performance - Running a script

Summary

I created a streamlit app that should run my simulation() function from a separate .py file. When I run the simulation function directly from the .py file it requires less than 1s to execute. However, running the same function from streamlit (after clicking a button), it requires >70s, which is a lot more…

I already read through the 6 Tips for Improving Your App Performance | Streamlit article. Also I make use of the @st.cache_data decorator and I set everything up so that already ran parameter configurations don’t need to be rerun again (they are very fast). So I am just talking about the performance of new parameter configurations here. In the mentioned article there is one sentence that says “And for static datasets you should always consider offloading computations to a file, to constants, or to a separate Python modules.” I am wondering what this means and if it could potentially be a solution.

Steps to reproduce

Code snippet:

if 'button_clicked' in st.session_state and st.session_state['button_clicked']:
    # compose adjusted parameters
    adjusted_params = new_params

    # Run the simulation.py script
    st.session_state['param_id'] = simulation(input_file_path, adjusted_params=adjusted_params)
    st.write(f"Simulation with id {st.session_state['param_id']} has finished based on these parameters:")
    st.dataframe(get_simulation_data('simulationData.db', 'sys_param'))
    st.success('Done!')


    # Reset the session state variable after running the simulation
    st.session_state['button_clicked'] = False

Debug info

  • Streamlit version: 1.27.2
  • Python version: 3.9.13
  • OS version: Windows
  • Browser version: Brave

Requirements file

radcad==0.8.4
pytest==6.2.2
ipykernel==5.5.3
matplotlib==3.3.4
stochastic==0.6.0
black==20.8b1
ipython-autotime==0.3.1
jupyter-dash==0.4.0
jupyter-client==6.1.2
jupyterlab==3.0.17
ipywidgets==7.6.3
notebook==6.4.1
pdoc3==0.9.2
jupyter-book==0.11.1
psutil==5.8.0
kaleido==0.2.1
nbconvert==5.6.1
flask==2.0.0
gunicorn==20.1.0
cadCAD_tools==0.0.1.4
tqdm==4.61.0
diskcache==5.2.1
pylint==2.8.3
jupyterlab-spellchecker==0.6.0
streamlit==1.27.2
altair<5
plotly==5.17.0

Links

Are there no ideas how to improve the performance?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.