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

Fix performance regression #6096

Merged
merged 1 commit into from
Mar 30, 2021
Merged

Fix performance regression #6096

merged 1 commit into from
Mar 30, 2021

Conversation

fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented Mar 29, 2021

Problem

Inner page components depending on the context render more often than before, and are significantly slower.

Root cause analysis

The introduction of useResourceLabel in #6016 forced a rerender of each view whenever an action is dispatched. That's because this new hook depends on a bad selector that creates a new result each time it is called:

export const getResources = state =>
Object.keys(state).map(key => state[key].props);

Therefore, in each of the main page controller (useListController, etc.), any change in the Redux store forces a re-run of the controller, which returns a new object, which updates the page context, which forces a rerender of all the components depending on it.

Solution

Do not use useSelector with that bad selector.

Before

13 renders of the <Datagrid> component in the Post list view in the simple demo:

image

After

7 renders of the <Datagrid> component in the Post list view in the simple demo:

image

@fzaninotto fzaninotto added the RFR Ready For Review label Mar 29, 2021
@fzaninotto fzaninotto added this to the 3.14.1 milestone Mar 30, 2021
@djhi djhi merged commit 7f8862d into master Mar 30, 2021
@djhi djhi deleted the fix-perf-regression branch March 30, 2021 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants