question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 https://github.com/Expensify/Expensify.cash/issues/3957#issuecomment-881045715 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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
marcaaroncommented, Jul 20, 2021

Sorry, I’m taking this over 😈

1reaction
marcaaroncommented, Jul 16, 2021

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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Performance] Conduct React Native Performance Audit #3957
I propose a React performance audit by investigating best practices in ... recreates props at each render, causing extraneous commits #4109 ...
Read more >
React re-renders guide: everything, all at once - Developer way
Comprehensive guide on React re-renders. The guide explains what are re-renders, what is necessary and unnecessary re-render, ...
Read more >
A (Mostly) Complete Guide to React Rendering Behavior
In normal rendering, React does not care whether "props changed" - it will render child components unconditionally just because the parent ...
Read more >
How to identify and resolve wasted renders in React
Building a React app where the differentiating algorithm fails to reconcile effectively, causing the entire app to be rendered repeatedly which ...
Read more >
Render and Commit - React Docs
There are two reasons for a component to render: It's the component's initial render. The component's (or one of its ancestors') state has...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found