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] Skip filtering if model didn't change #9112

Open
wants to merge 3 commits into
base: v6.x
Choose a base branch
from

Conversation

m4theushw
Copy link
Member

@m4theushw m4theushw commented May 24, 2023

Related to #8225

We're applying the filter whenever the model changes, which means that only opening the panel already triggers the filtering, even though the filter item has no valid value yet. With 100k rows this causes a perceptible freeze as can be seen in https://master--material-ui-x.netlify.app/x/react-data-grid/#commercial-version and reported in the issue above. This PR skips the filtering step if the new filter model, containing only items that have a value or don't need one, is different from the last time the filtering ran. As can be see below the performance improved a bit. I wished we could properly fix this issue by keeping a copy of the filter model used for the filter panel and only calling onFilterModelChange when the value is changed.

The comparison below was done against https://mui.com/x/react-data-grid/#commercial-version by measuring the time to change the column inside the filter panel.

Before:

image

After:

image

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

mui-bot commented May 24, 2023

Netlify deploy preview

Netlify deploy preview: https://deploy-preview-9112--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 309.1 470.8 358.3 383.96 64.335
Sort 100k rows ms 428.2 913.6 750.7 702.02 192.283
Select 100k rows ms 196.5 281.1 198.1 216.96 32.589
Deselect 100k rows ms 128.7 298.9 212.8 208.96 57.273

Generated by 🚫 dangerJS against a02d4ad

@m4theushw m4theushw added the feature: Filtering Related to the data grid Filtering feature label May 24, 2023
Copy link
Contributor

@romgrk romgrk left a comment

Choose a reason for hiding this comment

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

I'll just comment because I'm not familiar enough with that code yet. But I generally prefer to fix this sort of problem by avoiding touching the model until it needs updating, by keeping a local version of the model in the editing component that is only written to the model once it's ready to be written. Then again, I don't know the code so maybe this approach is easier, in which case this PR LGTM.

prevFilterModelWithOnlyValidItems.current,
);

if (skipIfNoValidItem && filterModelIsEqualToPrevious) {
Copy link
Member Author

Choose a reason for hiding this comment

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

It's opt-in because the filtering state is also used to track which groups are expanded or not. If we always run the check, when rowExpansionChange is fired it may not update the state. Maybe after #8671 we can revisit this part.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think after #8671 is merged, we can make it true by default.

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

github-actions bot commented Jun 1, 2023

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 Jun 5, 2023
@karanaditya993
Copy link

Hey @m4theushw @flaviendelangle we are running into issues where the onFilterModelChange callback is fired when you first open the filter panel

Do ya'll have a general estimate as to when this fix will go out? Thanks for your work on this, really appreciate it

@m4theushw
Copy link
Member Author

@karanaditya993 I don't have any estimation of when this PR will be merged, but note that it doesn't solve the problem you mentioned. When opening the filter panel and filterModel.items is empty, onFilterModelChange will still be called. It's only not called now if the model is the same from the last time that the filtering ran.

@karanaditya993
Copy link

karanaditya993 commented Jul 25, 2023

@karanaditya993 I don't have any estimation of when this PR will be merged, but note that it doesn't solve the problem you mentioned. When opening the filter panel and filterModel.items is empty, onFilterModelChange will still be called. It's only not called now if the model is the same from the last time that the filtering ran.

@m4theushw interesting...is this intentional? It seems like an unnecessary call (especially if onFilterModelChange is what dictates an external API call for server-side filtering) to make when you initially open the filter panel.

The idea here is that we'd want to only have the onFilterModelChange fired if you indeed do change any filters on the filter panel, but if they are initially being opened (and instantiated with empty values for the filter), calling onFilterModelChange seems redundant?

@karanaditya993
Copy link

I'm also noticing that when you open the filter panel from any of the columns (via the action menu on the column), the filterModel.items are never empty because they contain the field and operator of the column that you opened the panel from, even if the filter value is blank...so perhaps this PR does fix our use case

I will keep any eye out on the next few MUI releases to see if this is part of the release. In the meantime, I might copy paste the code you have here on an experimental fork to see if it resolves the issue we're having

Thanks again for your help and quick reply!

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

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

@MBilalShafi MBilalShafi changed the base branch from master to v6.x March 21, 2024 02:39
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 21, 2024
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! feature: Filtering Related to the data grid Filtering feature v6.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants