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

renderItem and renderItemTitle rerenders causes performance hits #291

Closed
ozolsg opened this issue Nov 17, 2023 · 1 comment
Closed

renderItem and renderItemTitle rerenders causes performance hits #291

ozolsg opened this issue Nov 17, 2023 · 1 comment
Assignees

Comments

@ozolsg
Copy link

ozolsg commented Nov 17, 2023

Describe the bug
When we use renderItem or renderItemTitle, props get called expanded tree list item amount of times. Even when functions are memoized. For smaller amount of list items the performance hit is not noticeable, when clicking or using up and down keyboard keys. However if we have a list of 1000 expanded items, performance hit is noticeable.

To Reproduce
Steps to reproduce the behavior:

  1. Open sandbox - https://codesandbox.io/s/react-complex-tree-playground-forked-9gszxq
  2. Expand tree structure
  3. Click on any item and check the amount of times renderItemTitle is being rerendered
  4. Navigate with up and down keyboard buttons and check how many times renderItemTitle is being rerendered
  5. The more items are expanded, the higher the amount of times rerendered

Expected behavior
renderItem and renderItemTitle elements not affected by keyboard presses or mouse clicks should not rerender.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome
  • Version: 119.0.6045.125
@lukasbach
Copy link
Owner

Hi!

Yes, the render method for items are retriggered on tree state changes, since every item is provided with information about the tree state in their props, so tree items wouldn't be able to display data they otherwise can.

You can memoize the item render methods directly with only those props that you use, this will ensure that items are not rerendered unless they need to be: https://codesandbox.io/s/react-complex-tree-playground-memo-demo-37mngx

lukasbach added a commit that referenced this issue Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants