jrieke / streamlit-analytics

👀 Track & visualize user interactions with your streamlit app
MIT License
262 stars 48 forks source link

Tracking all select/multiselect options can consume too much memory #37

Open mateusccoelho opened 1 year ago

mateusccoelho commented 1 year ago

Currently this package tracks all select/multiselect options, even if they are not selected. This maybe is a good feature because the option list can change during the app utilization. Still, we can't track which option were available to each user.

On the other hand, this can be problematic when using more than, say, 3000 options. Or when the label changes in execution time. The visualization in the analytics section becomes too large and this has the potential of using a lot of memory, since counts are stored in session state. That is, it's necessary to allocate a dict with 3000 string keys.

Example:

import streamlit as st
import streamlit_analytics as st_analytics

with st_analytics.track():
    val = st.multiselect('abc', list(range(5000)))

One thing that's supposed to be desirable with this package is to interfere as little as possible with the server's resources or with the user's code. So I propose to create a parameter in start_tracking so the user can choose to track all options. But it should be False by default, in which case _wrap_select and _wrap_multiselect should behave like _wrap_value.