-
Notifications
You must be signed in to change notification settings - Fork 866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Should I use Redux-persist if I have large objects in state? #185
Comments
What you are trying to do I suspect will always be somewhat expensive since you want to put all articles into a single Map. This is not a case that redux-persist handles particularly well out of the box. Off the top of my head, you might consider is storing each article under a separate key, possibly outside of redux entirely. Then in redux you can store a List with your article ids. Then whenever you need to fetch an article(s) you have an async get method that loads from storage. Hopefully that helps. Let me know what you ultimately end up figuring out, and if there is a clean way for redux-persist to help support this use case I am all ears. |
I'm also interested in performance considerations. I am retrieving tasks from the server (up to 10,000 at once), storing them in redux, and then persisting. I'm assuming that the persistence is the slowest part, it takes about 2 minutes to fully load and persist the data. Would changing the storage driver to Realm fix this? |
i found that redux-persist and async storage works fine for large amounts of data on ios but chokes in android. i have begun working on a solution but haven't fully integrated it yet: sriraman/react-native-shared-preferences#5 |
That's cool, good work :) Perhaps someone can clarify something for me, which I think may be the root of the problem. It looks here as though only the immediate substate or a redux store is diffed and updated or not, is that correct? If yes, then I believe that means that this: // Scenario A
// Store1 === [...manyThings], Store2 === [...manyThings], Store3 === [...manyThings],
persistStore(Store1);
persistStore(Store2);
persistStore(Store3); Would perform magnitudes better than this: // Scenario B
// Store === {Collection1: [...manyThings], Collection2: [...manyThings], Collection3:
// Collection1 === Store1, etc...
[...manyThings]}
persistStore(Store) Is that correct? To explain, in Scenario A, my collections are separated into a store for each. As documents come flooding in to |
@JulianKingman sceario A is workable in some scenarios, but I think there are ways to get scenario B to work for you as well. e.g.
|
@thorbenandresen , how did you solved this? |
I am also interested in potential solutions. My state has few large objects at 1st level (4-7 MB in total) which don't update much. Since the state is persisted under one key in v5, I am worried that it will be a big performance impact and battery drain for the device even when I change a boolean in some other key of the state. I tried using nested reducers for the large objects but unfortunately, I could not get them to persist at all! It will be great if someone can help out with an example. |
guys any ideas on how to speed this up or make it spin off in its own thread... async isnt cutting it |
I'm curious about this as well. How well can the library handle large objects? Does it persist constantly / after any change? |
Yes, that's the idea. You can use the throttle config option to partially mitigate this though.
Of course Realm would be faster, it's designed from the ground up with performance on large datasets in mind. This library is great for being something that can seamlessly slot into a Redux architecture, bringing with it all of Redux's benefits, but not the most performant choice if you're expecting lots of writes. |
Why or when did it got Choked? |
It's been asked by @cbfranca, but I'll ask again: @thorbenandresen, how did you solve this? Thanks in advance should you find the time to answer |
(This is amazing, it relieved me of a lot of pain I experienced with persisting my state manually. Thanks so much!)
My Situation
I am building a react-native app which is a client for pocket.co. So currently I query their REST API, convert the response into an Immutable.JS object and then load the object with the articles into my reducer and persist the entire article object via AsyncStorage.set(). When I then query the API for updates, I load my entire article object via AsyncStorage.get(), merge it with the updates and then load the merged article object into the reducer. I first render the articles when these operations have completed.
My article object:
Reading/Writing the article object from/to AsyncStorage (including JSON.stringify/parse) can be quite expensive when you have have lot of articles. I tested persisting the reducer the article object with redux-persist, but once I mutate the state (e.g. starring an article, deleting an article) my app gets very unresponsive and eventually crashes.
My Question
What are the best practices if you use redux as your database? Persisting the object manually with an object store like Realm or is there a way to make this work with redux-persist?
The text was updated successfully, but these errors were encountered: