-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[charts] Memoize series series selectors #20326
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
|
Deploy preview: https://deploy-preview-20326--material-ui-x.netlify.app/ Bundle size report
|
| export const selectorAllSeriesOfType = createSelector( | ||
| selectorChartSeriesProcessed, | ||
| <T extends keyof ChartsSeriesConfig>( | ||
| processedSeries: ProcessedSeries, | ||
| seriesType: T, | ||
| ): ProcessedSeries[T] => processedSeries[seriesType], | ||
| ); |
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.
@romgrk would it be possible (realistic) to create "generic" selectors?
This doesn't seem to properly work.
// Ideally the result of
useSelector(store, selectorAllSeriesOfType, 'bar')
// Would be `ChartSeriesDefaultized<'bar'>`
// But is a union of all possible `ChartSeriesDefaultized` variations.I tried looking at the types, but I guess you would know better before I delve too deep into this 😆
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.
Possible probably, realistic I don't know, sometimes types become quite complex, and I don't know how to fix this one.
|
Could you provide more information? What cases is this memoizing improving? Did you see any meaningful performance improvement? |
It was in draft, info should be up now 😆 |
bernardobelchior
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.
Looks good to me 👍
Both my comments are suggestions for improvements, but I realized that the code didn't change, so I think it's fine as is and we can consider tackling them as follow-ups.
| seriesType: T, | ||
| ids?: SeriesId | SeriesId[], | ||
| ) => { | ||
| if (!ids || (Array.isArray(ids) && ids.length === 0)) { |
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 realize this is how it works currently and it would be a breaking change to fix it, but just wanted to start this discussion:
If an empty array is provided shouldn't we return an empty array?
It's a bit weird that if you provide one ID you get one series, but if you provide zero IDs you get all the series.
We already have the optional ids field to mean "return all the series".
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.
added to #17955
| if (series) { | ||
| result.push(series); | ||
| } else { | ||
| failedIds.push(id); |
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.
If we don't want this to have a performance impact in production environments we can derive the failed IDs from result and ids inside the if statement.
Likely not a big deal, though
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.
Yeah I would assume this hook is not called with a lot of ids
This reverts commit ffb010d.
This reverts commit ffb010d.
In the original code I had a function that created the selectors.
The new code uses the arguments directly in the selector, which allows us to simply use the
useAllSeriesOfType/useSeriesOfTypeinstead of the generated values in eachuseSeriestypethen becomes
Realistically this shouldn't affect performance directly, but could improve re-renders for users by memoizing the result of the multi-series output (
useSeriesOfType('bar',[1,2,3...]);) when it returns an array.