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

Doc: Performance optimization for Nested List #3

Open
xhd2015 opened this issue Jun 22, 2024 · 1 comment
Open

Doc: Performance optimization for Nested List #3

xhd2015 opened this issue Jun 22, 2024 · 1 comment

Comments

@xhd2015
Copy link
Owner

xhd2015 commented Jun 22, 2024

Background: xgo renders 472 tree items in a nested list, a single click takes 127ms to take effect:

image

The profiler shows that the possible bottleneck is unnecessary re-rendering unrelated sub trees.

For example, in the above demonstration, only the ListItems with key="binding" should be updated while it seems all other sub trees were also evaluated, though nothing new happen.

So, use React.memo to optimize the ListItems:

const ListItemMemo = memo(ListItem, (prev, next) => {
    if (prev.item !== next.item) {
        return false
    }
    if (!isSamePath(prev.parentPath, next.parentPath)) {
        return false
    }
    return true
})

After this, a single click takes only 6ms to take effect:
image

NOTE: in the bottom area with grey background, profiler shows that ListItems with other keys "Did not render".

@xhd2015
Copy link
Owner Author

xhd2015 commented Jun 22, 2024

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

1 participant