-
Notifications
You must be signed in to change notification settings - Fork 862
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
V5 everything under single local storage key #489
Comments
@mauron85 thanks for the feedback. Ill explain the logic behind it, but yes there is probably room for further optimization, I am very open to new ideas on the matter. Why v5 works like it does
Performance: The double stringify then comes from the fact that we have a bunch of sub-states serialized, that we need to combine and serialize again before we can save to disk. I have done some very basic benchmarking - JSON.stringify of a stringified object is 100% - 150% faster than JSON.stringify of the original object. IMO worth the the tradeoffs. That said there is probably room for further optimization. e.g. since we know we are always storing an object of strings at the top level, perhaps there is a more compact and custom way to do the final serialization that does not require escaping the quotes in the sub state strings. |
Ok, it make sense to me now. Specially point 2. about state inconsistency. Also I think double stringify is not problem for now (but maybe can be improved like you said). What I don't understand is point 3. - nested persisted reducers. Can you give me some example what are those? |
in v5 this would work: let rootReducer = combineReducer({
a: persistReducer(persistConfigA, a),
b: persistReducer(persistConfigB, b),
}) so e.g. you might persist one set of state to sessionStorage and another to localForage. Or you might configure special rules in one to expire stored state on rehydration etc. |
That is actually pretty cool. In my react-native project I actually need to use two stores. One for small data and another one for quite large data. |
@rt2zz Can you plz tell me how to do this |
Raising this issue again, For the most part I understand the improvements that were mentioned by @rt2zz, though I'd like to better understand the benchmarking done on the Now, the reason I'm raising this issue again is because I want to emphasize two things we are losing when adding escaping characters or doing a double stringify.
Regarding the points for mentioned about V5
These are just a few opinions, but as always, they are just opinions, please let me know what you think. |
It seems that redux-persist-transform-filter now store everything under single key.
Whole state is persisted in localDb under single key:
persist:tracker = { entities: { deliveries: {} }}
In V4 separate key was created for every reducer:
reduxPersist:entities = { deliveries: {} }
, and so on.I think V4 is more performant as only slice of state will be serialised on state change (V4) vs serialising whole state atom (V5).
On screenshot V5 key is highlighted. Other keys are from V4
EDIT:
Also as seen on screenshot
{"entities":"{\"deliveries\":{}}"}
are unnecessarily double escaped.It seems that redux-persist is doing serialisation by calling JSON.stringify twice. This is also new in V5 (in V4 it was ok).
V5 seems to be doing
V4 seems to be doing
which will persist key's value as:
{"entities":{"deliveries":{}}}
The text was updated successfully, but these errors were encountered: