Open xhd2015 opened 1 week ago
Reference: React Memo: https://react.dev/reference/react/memo React Dev Tool: https://react.dev/learn/react-developer-tools React Profiler: https://legacy.reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html
You Might Not Need useEffect: https://react.dev/learn/you-might-not-need-an-effect
Background: xgo renders 472 tree items in a nested list, a single click takes 127ms to take effect:
The profiler shows that the possible bottleneck is unnecessary re-rendering unrelated sub trees.
For example, in the above demonstration, only the
ListItems
withkey="binding"
should be updated while it seems all other sub trees were also evaluated, though nothing new happen.So, use
React.memo
to optimize theListItems
:After this, a single click takes only 6ms to take effect:![image](https://github.com/xhd2015/coverage-visualizer/assets/14964938/baa9b941-1a53-4d1a-a884-04800164007b)
NOTE: in the bottom area with grey background, profiler shows that ListItems with other keys "Did not render".