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

[Performance] [Audit] withLocalizeHOC recreates props at each render, causing extraneous commits #4109

Closed
jsamr opened this issue Jul 16, 2021 · 15 comments

Comments

@jsamr
Copy link
Collaborator

jsamr commented Jul 16, 2021

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


This report is part of #3957, scenario "Rendering Individual chat messages".

Commit Log

The full commit log can be inspected with Flipper or React Devtools, see #3957 (comment) for instructions.

I noticed that SidebarLinks component would often rerender. If you look at c72 and select SidebarLinks, you'll notice it's rendered 6 times during the session. 3 of those 6 commits are caused by props from withLocalizeHOC, see screenshot below:

image

Cause

withLocalize is a central HOC used massively throughout the App. Yet, each prop it passes (translate, numberFormat, timestampToRelative...) is an inline function recreated on each render.

https://github.com/Expensify/Expensify.cash/blob/92429b5411bc8d050e2aae157dae27da2a3d0f68/src/components/withLocalize.js#L33-L46

Proposal 1: use memoization

Make sure those props are memoized via a class component bound methods or hooks.

Proposal 2, test rendering performance of withLocalizeHOC

Test performance-critical withLocalizeHOC with react-performance-testing to enforce rendering metrics, such as number of renders in controlled conditions.

EDIT: added Proposal 2

@jsamr jsamr added the AutoAssignerTriage Auto assign issues for triage to an available triage team member label Jul 16, 2021
@MelvinBot
Copy link

Triggered auto assignment to @alexpensify (AutoAssignerTriage), see https://stackoverflow.com/c/expensify/questions/4749 for more details.

@MelvinBot MelvinBot removed the AutoAssignerTriage Auto assign issues for triage to an available triage team member label Jul 16, 2021
@parasharrajat
Copy link
Member

parasharrajat commented Jul 16, 2021

Wow! nice catch. useMemo or 'useCallback' will do the trick.

Edit:
Just checked, I think this will make a big impact.

@MelvinBot
Copy link

Triggered auto assignment to @NikkiWines (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

@marcaaron
Copy link
Contributor

Looks pretty straight forward and has an easy solution. Curious to see how many net re-renders we could prevent by memoizing these callbacks. Should be a good metric to justify implementing.

@jsamr
Copy link
Collaborator Author

jsamr commented Jul 16, 2021

Curious to see how many net re-renders we could prevent by memoizing these callbacks. Should be a good metric to justify implementing.

@marcaaron That would be very cumbersome to investigate, but not impossible! However we know that this HOC is referenced in 90 files, I believe the impact will be pretty significant!

@NikkiWines NikkiWines added the External Added to denote the issue can be worked on by a contributor label Jul 16, 2021
@NikkiWines NikkiWines removed their assignment Jul 16, 2021
@MelvinBot
Copy link

Triggered auto assignment to @NicMendonca (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

@marcaaron
Copy link
Contributor

That would be very cumbersome to investigate, but not impossible

For sure, apologies, to be clear I wasn't asking for you to do this - just that it would be interesting to see data :)

@MelvinBot MelvinBot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Jul 19, 2021
@MelvinBot
Copy link

Triggered auto assignment to @NikkiWines (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@NicMendonca
Copy link
Contributor

Posted to Upwork: https://www.upwork.com/jobs/~012f859a8ff2c9153a

@marcaaron
Copy link
Contributor

Sorry, I'm taking this over 😈

@marcaaron marcaaron assigned marcaaron and unassigned NicMendonca Jul 20, 2021
@marcaaron marcaaron removed Exported External Added to denote the issue can be worked on by a contributor labels Jul 20, 2021
@MelvinBot
Copy link

@NikkiWines, @NicMendonca Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@parasharrajat
Copy link
Member

I think we should remove the Help Wanted label and close this issue as well. The fix is patched.

@marcaaron marcaaron removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Jul 26, 2021
@MelvinBot
Copy link

@marcaaron Still overdue 6 days?! Let's take care of this!

@marcaaron
Copy link
Contributor

This issue is on staging now so bumping down to weekly it should be fixed soon.

@MelvinBot MelvinBot removed the Overdue label Jul 27, 2021
@marcaaron marcaaron added Weekly KSv2 and removed Daily KSv2 labels Jul 27, 2021
@marcaaron marcaaron removed their assignment Aug 11, 2021
@MelvinBot MelvinBot removed the Overdue label Aug 11, 2021
@marcaaron
Copy link
Contributor

This can be closed I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants