Use st.experimental_singleton for heavy objects

Hi,

As per my understanding st.experimental_singleton does not serialize the returned objects and keeps them in memory for all users of the same app, while st.experimental_memo seralizes/deserializes the objects at each run of the app and keeps a different copy for each user.

The doc recommends to use experimental_memo when the returned object is a data object. But I see that when this object is quite heavy (several 100Mb) the deserialization process takes time and makes the app very slow. Knowing that my app does not mutate the returned object and that I want a single version of this object for all users, is it a good decision to use experimental_singleton instead (despite the doc not recommending it) ? What could be down sides ?
Thanks

1 Like

This is a great question

Where in the docs does it say โ€œst.experimental_memo serializes/deserializes the objects at each run of the app and keeps a different copy for each userโ€? (I havenโ€™t read that anywhere.)

Itโ€™s here

Each caller of a memoized function gets its own copy of the cached data.

Thanks, so each caller gets their own copy because itโ€™s call-by-value, not call by reference.

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