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

PRESS 2 498 | Audit memoization candidates #157

Merged
merged 26 commits into from
Feb 15, 2023

Conversation

officiallygod
Copy link
Member

@officiallygod officiallygod commented Jan 24, 2023

Added a few improvements so as to reduce the number of rerenders in the commonly used pages throughout the Onboarding Module

@officiallygod officiallygod added WIP PR is a Work in Progress and not ready for review. Post Phase 2 Polish Polish PR's for work done in Phase 2 labels Jan 24, 2023
@officiallygod officiallygod removed the WIP PR is a Work in Progress and not ready for review. label Jan 28, 2023
Copy link
Member

@arunshenoy99 arunshenoy99 left a comment

Choose a reason for hiding this comment

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

Hey Allen, added one code comment and then these are a few things we need to take a look at
Top 3 Potential Memoization Opportunities (I am not an expert so might be wrong on a few of these)

  1. The Common Layout used across onboarding is being re-rendered causing a domino effect re-rendering all its children as well?
    Screenshot 2023-02-01 at 1 36 45 PM

  2. Sidebars are rendered 3 times on every page + 1 render on open.
    Screenshot 2023-02-01 at 12 29 45 PM

  3. The drawer is being rendered multiple times?
    Screenshot 2023-02-01 at 1 51 29 PM

Important Note
Can we check if the changes here are the correct way to use memo? If I am not wrong effective memoization flows starting from the parent to the child so that a small parent re-render does not result into a big expensive child re-render(like our previews and the common layout), please take a look at a few of these links that helped me understand memoization, https://dmitripavlutin.com/use-react-memo-wisely/, https://medium.com/@vitaliysteffensen/how-i-eliminate-all-unnecessary-rerenders-in-react-79505deeedea and WordPress/gutenberg#25780

Based on the note I am not sure if we have missed more potential opportunities, please do take a look at those other than the top 3 as well.

@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { get, isEmpty, kebabCase, pickBy, reduce, set } from 'lodash';
import { get, isEmpty, kebabCase, pickBy, reduce, set, memoize } from 'lodash';
Copy link
Member

@arunshenoy99 arunshenoy99 Feb 1, 2023

Choose a reason for hiding this comment

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

Sorry for pointing this out a bit late, let's avoid adding more dependencies on lodash? It seems like Gutenberg has made a commitment to remove the lodash dependency from it's packages which we are keeping an eye on. I was going through some of the PR's there and found that https://www.npmjs.com/package/memize is being used as a replacement to the lodash memoize(attaching why in ref), can we explore this?
Ref:
Lint config of Gutenberg preventing lodash dependencies recommending memize: https://github.com/WordPress/gutenberg/blob/d9da1250c77d3dc083729b72b8143dfc7bc222ba/.eslintrc.js#L157
Why: WordPress/gutenberg#6686 (comment)

officiallygod and others added 7 commits February 2, 2023 16:07
Memoized Header
Removed unused code
Removed unused imports
Removed unused props
Added Memoization to Drawer
Rearranged Imports
Added Memoized support for Sidebar
@officiallygod officiallygod changed the title PRESS 2 498 Audit memoization candidates PRESS 2 498 | Audit memoization candidates Feb 7, 2023
Copy link
Member

@arunshenoy99 arunshenoy99 left a comment

Choose a reason for hiding this comment

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

Let's remove the build changes? they can cause a conflict anything changes in trunk

@officiallygod officiallygod self-assigned this Feb 9, 2023
@arunshenoy99 arunshenoy99 merged commit d97de02 into trunk Feb 15, 2023
@arunshenoy99 arunshenoy99 deleted the PRESS-2-498-Audit-Memoization-Candidates branch February 15, 2023 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Post Phase 2 Polish Polish PR's for work done in Phase 2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants