-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
[Performance] Slice contexts (createSliceWithContext) #2202
Comments
Agreed that the That said, if I'm understanding this proposal right, the approach here isn't viable. There's no guarantee that a given subtree will only ever access a specific slice of state. The whole point of |
@markerikson you can see that So yes, it will access only a specific slice. And yes, this optimization makes sense only for huge apps. |
Yeah, that's not something we plan to implement ourselves. (I do have a general interest in ideas to optimize React-Redux perf, but it's not something I have time to look into atm.) |
@markerikson OK, I updated header a bit with idea to create a |
Other possible ways to reach that:
|
Just to throw the idea out - with something like |
Yeah, that's roughly similar to what I was playing around with in this PR: but A) I haven't ever had time to go back and play with that idea again, B) I'm pretty sure there's a ton of edge cases this would have issues with, and C) it requires an up-front fixed set of work (reconciling the immutably updated state tree into the proxy wrapper) and the cost of reading from proxies (which I recently found out can be relatively expensive), and it's very questionable if the amount of time saved from skipping subscribers and selectors would actually be a net improvement in perf. I can say that apparently Slack did do something similar to this "domains" proposal in terms of watching for top-level slice changes, but it sounds like they did it by wrapping the store subscription process itself and providing methods for consumers to subscribe to just those keys, thus providing some fan-out behavior. (Also, evidence that this can be done in userland, and thus not something I would want to build in to the lib itself any time soon.) In fact, I actually just went back and looked at the list of Redux addons I kept updated between 2016 and 2018, and I see several plausible-sounding "only subscribe to a specific piece of the state" libs here:
Alternately, @gentlee , you might want to look at https://www.npmjs.com/package/redux-subspace . It's deprecated, but I think the API is actually pretty similar to what you're asking for, and the README lists a few other alternative libraries. |
What is the new or updated feature that you are suggesting?
Problem:
One of the slowest parts of redux is that there can be a lot of subscribers to the store with their custom state comparers. If we have 1000 subscribers and 100 actions are triggered per second (like on startup of the chatting app), 100 000 comparisons are made per second.
One possible solution is to use multiple stores, but this can lead to various issues.
Suggestion:
The same performance of having multiple stores can be achieved with single store. There is already an ability to make custom contexts and hooks, but currently it makes sense only for multiple stores.
UPDATED: Ability to provide the same store but with slice's context and hooks should be added with the new
createSliceWithContext
function:Please also check the initial suggestion as it provides more generic solution, and can be implemented as well / instead:
OLD
Ability to provide the same store but with domain selector should be added:Why should this feature be included?
This will make using multiple stores totally obsolete, but will fix performance issues caused by single store.
What docs changes are needed to explain this?
https://react-redux.js.org/using-react-redux/accessing-store
Add recommended practise here:
https://redux.js.org/style-guide/
The text was updated successfully, but these errors were encountered: