Skip to content

Doc: Performance optimization for Nested List #3

@xhd2015

Description

@xhd2015

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".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions