-
Notifications
You must be signed in to change notification settings - Fork 2k
Comments: invalidate createSelector cache based on state.comments.items instead of posts #17585
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
Conversation
…ms instead of specific posts
the simple answer is that no we aren't 😉 a better assessment would be that we are poorly documenting the behavior or choosing a poor wording to describe it. it's not really a memoized function; we have a function which caches its last execution and uses a custom cache invalidator based on reference equality. if it truly were memoized it would balloon in memory. in Simplenote Electron in a now-closed PR I created a wrapper function my advice here is to think through and list out the tradeoffs in this design (and without it). those tradeoffs and the reason for choosing this option belong in the JSDoc comment above the selector. true memoization would balloon in memory because it would store the results of every invocation of this function (and it would use the inputs as the cache key for retrieval, not for invalidation) using are we guarding against re-renders? against updates from the server? would a capped cache better serve than a single-cache? I'm a vocal critic of |
I stand by my assertion that there exists a cache and we are invalidating it too frequently. I have a feeling that the current The change I'm proposing here does involve a classic space vs. time tradeoff. Its a necessary trade for conversations tool...but i'll get to that in a bit
current:
proposed:
Background on why I'm making this: I'd also argue that this PR simplifies the dependent rather than making it more complex. I would have wanted a comment for the old version explaining the counterintuitive behavior whereas the version in this PR follows the fairly standard pattern for using |
gwwar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think changes here make sense and they test well. 👍
If we still run into perf problems we may want to consider our stance on either normalization of comments (maybe we should add a few other reducers to help us, keeping in mind that we should take care if we ever persist any of this data) or if we need a more custom caching solution.
|
Discussed with @dmsnell on slack, he gave me a verbal OK. |
This may be me misunderstanding how to use the
createSelectorhelper function, but my current impression is that we are over-invalidating the cache. Ideally we could invalidate the cache for specific posts when the comments for a post are modified, but thats not possible with the current implementation ofcreateSelector.Something I am seeing regularly now is:
This PR seeks to invalidate the cache when
state.comments.itemschanges instead of when the post selected for changes