-
Notifications
You must be signed in to change notification settings - Fork 671
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
First level of cascading memoization is broken when more props are passed #715
Comments
That sounds like things are working as expected:
So yes, passing a new object reference to a selector is not a good idea. Have you tried passing them as separate arguments instead? |
That's what we are migrating to right now. But this still doesn't solve the original issue. I understand why it works like that but many devs at first were a bit lost when I told them about first level of cache cascade and that prop selectors ideally should be written like
instead of passing input selectors directly
So what do you think, is it something that should be handled by the library? E.g. one more input dev check, note in docs or a solution? |
I don't think there's anything we should change here. Relying on I think your best bet is to customize |
Got it, thanks for your opinion 🙇🏻 Closing the issue then |
Hello,
Not sure it's an issue but want to highlight this small problem we faced recently.
So imagine you have two selectors:
as a result whenever
getItem
is called it also callsgetSchema
with arguments:state
anditemId
which leads to invalidation of args memoization.Usually overhead might be unnoticeable because second level of caching still works but for some 'hot' selectors we see some significant numbers.
Here is an example for one of our hottest selectors after reloading the page. And every dispatch generates few thousands of dependency recomputations
Right now I can see 3 ways how it can be fixed in userland:
const acceptStateOnly = (selector) => (state) => selector(state)
and wrap such hot selectors at place where they are definedargsMemoize
to care about first argument onlyI don't really like them as they are pretty fragile so I wonder if it's something that can be improved on library side, e.g. by comparing length of incoming arguments with length of saved arguments or by stricter types or by advanced input stability check
Thanks in advance 🙇🏻
P.S. also the issue is so noticeable for us because we used to pass props as object to selectors like
useSelector((state) => selector(state, {prop1, prop2}))
which basically leads to args cache invalidation on every react renderThe text was updated successfully, but these errors were encountered: