Skip to content

Conversation

@alexfauquette
Copy link
Member

@alexfauquette alexfauquette commented Oct 22, 2025

First step for #20046 I do as few renaming as possible

Still need to work on the memoization aspect: Which selector should be memoized or not

@alexfauquette alexfauquette added the scope: charts Changes related to the charts. label Oct 22, 2025
@mui-bot
Copy link

mui-bot commented Oct 22, 2025

Deploy preview: https://deploy-preview-20052--material-ui-x.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/x-data-grid 🔺+343B(+0.09%) 🔺+38B(+0.03%)
@mui/x-data-grid-pro 🔺+343B(+0.07%) 🔺+57B(+0.04%)
@mui/x-data-grid-premium 🔺+343B(+0.05%) 🔺+44B(+0.02%)
@mui/x-charts 🔺+1.56KB(+0.46%) 🔺+434B(+0.43%)
@mui/x-charts-pro 🔺+1.45KB(+0.33%) 🔺+430B(+0.32%)
@mui/x-charts-premium 🔺+1.48KB(+0.34%) 🔺+441B(+0.34%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 🔺+343B(+0.53%) 🔺+71B(+0.36%)
@mui/x-tree-view-pro 🔺+15B(+0.02%) 🔺+10B(+0.04%)

Details of bundle changes

Generated by 🚫 dangerJS against 815b6cf

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 22, 2025

CodSpeed Performance Report

Merging #20052 will improve performances by 10%

Comparing alexfauquette:no-renamining (815b6cf) with master (49816fd)1

Summary

⚡ 4 improvements
✅ 9 untouched

Benchmarks breakdown

Mode Benchmark BASE HEAD Change
Simulation BarChart with big data amount 2 s 1.8 s +9.95%
Simulation SankeyChart with big data amount 125.8 ms 115.2 ms +9.17%
Simulation ScatterChartPro with big data amount and zoomed in (single renderer) 71.3 ms 64.9 ms +9.83%
Simulation ScatterChartPro with big data amount and zoomed in (batch renderer) 72 ms 65.5 ms +10%

Footnotes

  1. No successful run was found on master (d2a635b) during the generation of this report, so 49816fd was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 22, 2025
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 22, 2025
Comment on lines +188 to +189
const propsWidth = useSelector(store, selectorChartPropsWidth);
const propsHeight = useSelector(store, selectorChartPropsHeight);
Copy link
Member Author

Choose a reason for hiding this comment

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

Use selectors that return number to avoid having to memoize those

store,
selectorSeriesWithIds,
ids,
// fastArrayCompare
Copy link
Member Author

Choose a reason for hiding this comment

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

Would be nice but not urgent to bring that logic.

The issue it solves is the following one:

If any processesd series get updated, the follwoing hook will trigger a re-render, because it returns a new array of series. Event if the objects are exactly the same

const specialSeries = useBarSeries(['id1', 'id2'])

Copy link
Member

Choose a reason for hiding this comment

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

Could we spread the IDs? useBarSeries('id1', 'id2')?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really because selectors are limited to 3 args. so 3 ids in that case.

But the more I think about it, the more I consider we could remove the array option

Copy link
Member

Choose a reason for hiding this comment

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

But the more I think about it, the more I consider we could remove the array option

It would be a breaking change, wouldn't it?

I guess it can make sense if you have programmatically generated series, though. Otherwise you need N hooks for N series.

Copy link
Member

Choose a reason for hiding this comment

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

I guess it can make sense if you have programmatically generated series, though. Otherwise you need N hooks for N series.

you can always provide no array and get all series, albeit the result shape is different

It would be a breaking change, wouldn't it?

yeah

we could do something like useBarChart([1,2,3]) => arg0.map(v => series[v]) though

: acc,
0,
),
export const selectorChartAxisSizes = createSelectorMemoized(
Copy link
Member Author

Choose a reason for hiding this comment

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

I grouped all the axis sizes in a single memoized object to reduce the number of selectors for drawing area

Comment on lines 93 to 102
[
selectorChartRawXAxis,
selectorChartSeriesProcessed,
selectorChartSeriesConfig,
selectorChartZoomOptionsLookup,
selectorChartDrawingArea,
selectorChartPreviewXScales,
selectorChartXDomains,
(_, axisId: AxisId) => axisId,
selectorChartXAxisWithDomains,
],

(
Copy link
Member Author

Choose a reason for hiding this comment

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

This selector was exceeding the number of allowed selectors.

Since selectorChartXDomains has selectorChartRawXAxis as an input, I modified selectorChartXDomains to return both the domains and the raw axes

Comment on lines 147 to 154
// {
// memoizeOptions: {
// // Keep the same reference if array content is the same.
// // If possible, avoid this pattern by creating selectors that
// // uses string/number as arguments.
// resultEqualityCheck: isDeepEqual,
// },
// },
Copy link
Member Author

Choose a reason for hiding this comment

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

We should bring that back

The selectors get the pointer x-coordinate, and the x-axes. From that it derives axes data indexes associated to the pointer.

This isDeepEqual was here to update the value only when the pointer moves from one value to another.

@romgrk Woudl you be ok if we add an option in createSelectorMemoized to modify the memoizeOptions?

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's not possible to inline the arguments to avoid the array, then yes we could, but that sounds like a hack so I would avoid it if possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've inlined the one I could, but this one does not look feasible

},
},
);
store.set('voronoi', { isVoronoiEnabled: !disableVoronoi });
Copy link
Member Author

Choose a reason for hiding this comment

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

The voronoi state only have isVoronoiEnabled property

Comment on lines 108 to 116
// {
// memoizeOptions: {
// // Keep the same reference if array content is the same.
// // If possible, avoid this pattern by creating selectors that
// // uses string/number as arguments.
// resultEqualityCheck: isDeepEqual,
// },
// },
);
Copy link
Member Author

Choose a reason for hiding this comment

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

Same issue as in the cartesian axes

@alexfauquette alexfauquette added the type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. label Oct 27, 2025
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 29, 2025
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 29, 2025
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 30, 2025
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 30, 2025
@alexfauquette alexfauquette marked this pull request as ready for review October 30, 2025 10:29
@alexfauquette alexfauquette changed the title Use the internal store [charts] Use selectors from @mui/x-internals Oct 30, 2025
},
);

const noop: AxisItemIdentifier[] = [];
Copy link
Member

Choose a reason for hiding this comment

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

Might be more descriptive:

Suggested change
const noop: AxisItemIdentifier[] = [];
const EMPTY_ARRAY: AxisItemIdentifier[] = [];

/**
* Method wrapping reselect's createChartSelector to provide caching for chart instances.
*/
export const createSelector = <
Copy link
Member

Choose a reason for hiding this comment

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

I suppose this is meant as a stepping stone to remove later, right? What's preventing us from using the createSelector from the x-internals store directly?

Copy link
Member Author

Choose a reason for hiding this comment

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

To do so you would have to modify all the selectors because of a small difference. Si it's mostly to avoid useless diff in the initial PR

// our
createSelector([select1, select2], combiner)

// internal
createSelector(select1, select2, combiner)

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense.

Do we want to migrate to the new API or keep our current one? Just so we align on new selectors

Copy link
Member Author

Choose a reason for hiding this comment

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

I would be in favor of moving to the new selectors API.

That's why I directly imported the memoized one.
For the migration we would "just" have to replace all the imports and remove the [] around selectors

store,
selectorSeriesWithIds,
ids,
// fastArrayCompare
Copy link
Member

Choose a reason for hiding this comment

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

Could we spread the IDs? useBarSeries('id1', 'id2')?

Copy link
Member

@bernardobelchior bernardobelchior left a comment

Choose a reason for hiding this comment

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

Thanks for this 🙏

: acc,
0,
),
export const selectorChartLeftAxisSize = createSelectorMemoized(
Copy link
Member

Choose a reason for hiding this comment

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

Why are these memoized if they return a number? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably nothing 🫣

Copy link
Member

@JCQuintas JCQuintas left a comment

Choose a reason for hiding this comment

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

no issues, only questions 😆

@JCQuintas JCQuintas enabled auto-merge (squash) October 31, 2025 14:42
@JCQuintas JCQuintas merged commit f775e82 into mui:master Oct 31, 2025
22 checks passed
mapache-salvaje pushed a commit to mapache-salvaje/mui-x that referenced this pull request Dec 29, 2025
Co-authored-by: Jose Quintas <juniorquintas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: charts Changes related to the charts. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants