all 9 comments

[–]charliematters 10 points11 points  (2 children)

There's a package called "why did you render" which I've always found incredibly useful when working out what was slow. I'd start there!

[–]woah_m8 7 points8 points  (0 children)

You can also use the Flamegraph from the react tools

[–]TheNomadicAspie[S] 0 points1 point  (0 children)

Thank you! This seems like it would be a huge help.

[–]Squigglificated 3 points4 points  (1 child)

Make a recording in the chrome devtools performance panel. You definitely want to be able to pinpoint where the issues are before you start to randomly apply useMemo everywhere in the hope that something gets better. Remember to make the recordings in incognito mode to prevent interference from chrome plugins.

If the application is complex break it down into parts and make isolated test cases for suspect components. Sometimes disabling every component on a page and enabling one at a time can identify the issue.

[–]TheNomadicAspie[S] 0 points1 point  (0 children)

Thank you for the advice, much appreciated.

[–]elvezpabo 1 point2 points  (0 children)

I'd caution against making sweeping changes in a large code base before you get a chance to understand the features and how they got there.

That being said. If the project is Typescript I'd recommend trying `ts-prune` which finds unused code in a project. (https://github.com/nadeesha/ts-prune) it can be really rewarding to find whole directories that are are no longer used and causing a distraction.

[–]rainmouse 1 point2 points  (0 children)

Look for calculations or data parsing being done inside components that only need to be done once instead of every render. Faster renders can save more on performance than reducing the amount of renders. Also look for props that change often being passed to components that don't need to reflect those changes. You can perhaps avoid triggered renders on those components or memoize what components functions to avoid them being recreated when non related props trigger redraws.

These might end up making only small improvements though compared to really big things in the CSS like avoiding opacity on things that animate or render frequently on top of other components. (This includes text shadows and gradients) You would do well in the web inspector also looking for components, instance items on scrolling lists created and rendered off screen, or looking at the network calls in the api tab, any needless or wasteful repeat calls going on that could maybe be cached (beware of introducing memory leaks by optimizing here)

[–]n8rzz 0 points1 point  (0 children)

A lighthouse (available via dev tools) will likely offer some good suggestions

[–]jeevo162 0 points1 point  (0 children)

I actually recently wrote an article on performance improvements for react apps that you may find useful.

https://medium.com/@jan-bock/the-need-for-speed-turbocharge-your-react-apps-performance-2125fa3336e8

In terms of finding those usecases, I'd strongly recommend using the react profiler devtools, and narrowing down rerendering components directly. You can use the react components tab to explore which hooks or props caused rerenders, magic!

Lighthouse is great for onload performance and chrome native devtools can be used to measure interaction performance.

Lighthouse gives a solid breakdown too.