Cached data reloads slower than desired

I’ve just started exploring Streamlit, so my apologies if my questions are somewhat basic.

I understand that Streamlit reexecutes my entire script after after user interaction.

My data is contained in a data frame with the following characteristics:

<class 'pandas.core.frame.DataFrame'>
Index: 2641258 entries, 0 to 1495
Data columns (total 12 columns):
 #   Column           Dtype
---  ------           -----
 0   Airport          object
 1   Terminal         object
 2   Date             object
 3   Time Range       object
 4   US Max Wait      int64
 5   Non US Max Wait  int64
 6   All Max Wait     int64
 7   Time             object
 8   Datetime         datetime64[ns]
 9   Year             int32
 10  Month            object
 11  Weekday          object
dtypes: datetime64[ns](1), int32(1), int64(3), object(7)
memory usage: 251.9+ MB

Loading this from a (compressed) pickled file the first time takes about 5.5 seconds. The load routine is annotated with @st.cache_data but still takes over 1.2 seconds to reload the data after each and every user interaction, which is rather slower than I was hoping for.

What’s the best practice approach to speeding up the user response, please?

(A version of the app, with less data, and hence a rather snappier response, is available at https://airportwaitingtimes.streamlit.app/)

You are already using the @st.cache_data decorator so one way to speed up the user response could be to optimize the function being cached. You could also try adjusting the parameters of the st.cache_data decorator, such as max_entries, ttl, and persist, to see if they have any effect on the performance

Many thanks. I wrote some more functions which returned only a part of the underlying data and that seemed to speed things up. There’s still a hiccup when it has to go back for the second part of the data as it involves accessing the entire data frame again, but I’ll look at that later.

Again, thanks,

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