Skip to content
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

WIP: Allow createSelector to store a cache #21547

Closed
wants to merge 1 commit into from

Conversation

dmsnell
Copy link
Member

@dmsnell dmsnell commented Jan 15, 2018

@see #20330 which is basically the same except this PR makes the behavior global and default
@see #20547 which provides an explicit and robust way of caching

This is exploratory and may be fundamentally flawed but I'm opening it for the discussion because maybe, just maybe it's a good decision.

createSelector has a big problem: it invalidates its cache way too
frequently. It does this whenever dependants change, but it's not
comparing those dependants against the called parameters - it's applying
them "globally" within the selector such that even when the underlying
data in state is the same, because the selector was invoked with
different parameters it generates different dependants and thinks things
are different.

This change caches the dependants per cache key so we don't need to
clear so often. This introduces memory bloat because we're storing those
cached values throughout the session.

@@ -139,7 +140,7 @@ export function buildExportArray( data, parent = null ) {
* @return {String} Serialized stats query
*/
export function getSerializedStatsQuery( query = {} ) {
return JSON.stringify( sortBy( toPairs( query ), pair => pair[ 0 ] ) );
return deterministicStringify( query );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops. this wasn't necessary for this PR but it was in my stash

@dmsnell dmsnell force-pushed the refactor/create-selector-store-moar branch from 807c940 to 787a31a Compare January 15, 2018 23:22
`createSelector` has a big problem: it invalidates its cache way too
frequently. It does this whenever dependants change, but it's not
comparing those dependants against the called parameters - it's applying
them "globally" within the selector such that even when the underlying
data in `state` is the same, because the selector was invoked with
different parameters it generates different dependants and thinks things
are different.

This change caches the dependants per cache key so we don't need to
clear so often. This introduces memory bloat because we're storing those
cached values throughout the session.
@dmsnell dmsnell force-pushed the refactor/create-selector-store-moar branch from 787a31a to c9c0203 Compare January 25, 2018 16:54
@dmsnell
Copy link
Member Author

dmsnell commented Apr 12, 2018

Closing because people didn't want to investigate if this is a problem and I am too busy to do it myself.

@dmsnell dmsnell closed this Apr 12, 2018
@dmsnell dmsnell deleted the refactor/create-selector-store-moar branch April 12, 2018 11:29
@aduth
Copy link
Contributor

aduth commented Apr 18, 2018

What was this meaning to resolve which wasn't already covered by #20547 ?

Possibly of interest: aduth/rememo#1 , which achieves a bit of both between Calypso's createSelector and treeSelect.

@dmsnell
Copy link
Member Author

dmsnell commented Apr 19, 2018

@aduth it was trying to resolve the question of how much our current use of createSelector is slowing down the app due to cache-thrashing. if we replaced every use of createSelector with treeSelect we wouldn't have any reason to ask this question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants