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

[DataGrid] Fix row id bug #10051

Merged
merged 4 commits into from
Aug 16, 2023
Merged

[DataGrid] Fix row id bug #10051

merged 4 commits into from
Aug 16, 2023

Conversation

romgrk
Copy link
Contributor

@romgrk romgrk commented Aug 16, 2023

Fixes #9915 (comment)

Add a api.getRowId method and use it in the aggregation code. We should eventually migrate all our row.id accesses to that function, it ensures we use the getRowId prop and the GRID_ID_AUTOGENERATED if applicable.

@romgrk romgrk added the component: data grid This is the name of the generic UI component, not the React module! label Aug 16, 2023
@mui-bot
Copy link

mui-bot commented Aug 16, 2023

Netlify deploy preview

Netlify deploy preview: https://deploy-preview-10051--material-ui-x.netlify.app/

Updated pages

No updates.

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms -185.2 64.8 -99.4 -41.78 91.849
Sort 100k rows ms 720.8 1,493.9 1,461.8 1,299.8 291.221
Select 100k rows ms 613.7 865.9 714.1 738.88 86.106
Deselect 100k rows ms 112.4 311 208.6 211.68 62.986

Generated by 🚫 dangerJS against 530964b

@@ -109,6 +109,19 @@ export const useGridRows = (
[apiRef],
);

const getRowId = React.useCallback<GridRowApi['getRowId']>(
Copy link
Member

Choose a reason for hiding this comment

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

I was wondering about the performance of this.

And if like AG Grid, it can make sense to have an intermediary data structure for caching https://www.ag-grid.com/javascript-data-grid/client-side-row-stages/#state-2-all-rows

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which kind of performance hit are you worried about?

And I'm not sure how that structure applies here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The apiRef.current indirection might prevent optimization, but I think if we destructure the API method into a const before usage like const getRowId = apiRef.current.getRowId it becomes very very easy for the JITs to optimize it away with inlining, and the if (getRowIdProp) branch is also optimized away in most cases due to getRowIdProp being a const undefined.

But we can keep that for cases where it matters. In the case for this PR it doesn't matter enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh actually it's for filtering, so it might matter. I'll benchmark at some point and decide from there.

Copy link
Member

@oliviertassinari oliviertassinari Aug 16, 2023

Choose a reason for hiding this comment

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

Which kind of performance hit are you worried about?

I was wondering of the time it take to access row.id vs. calling getRowId(row) when we do it a lot of time, e.g. sorting 100,000 rows client side, but also filtering, grouping, pivoting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be nice to avoid, but let's start with correctness and we can benchmark performance again soon, I'm completing one more perf change and I'll be done with the work from #9120. Anyway I think we've gained enough performance lately to afford one more fcall in there :)

@romgrk romgrk merged commit f36185a into mui:master Aug 16, 2023
4 checks passed
@romgrk romgrk deleted the fix-row-id-bug branch August 16, 2023 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants