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

Improve performance and add memorization #130

Merged
merged 6 commits into from
Dec 6, 2021
Merged

Improve performance and add memorization #130

merged 6 commits into from
Dec 6, 2021

Conversation

Nerevar123
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

  • [х] Tests for the changes have been added (for bug fixes / features)
  • [х] Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[x] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the new behavior?

Hi @amcdnl, I checked all the Canvas & Node props and added memorization where the props are causing re-render every time. It`s not solve the problem completely yet, but the app works much faster with memorization.

I also added a new story with 30 nodes, all possible props are written in it, adding them prevents re-renders (something is wrong with the default values)

P.S.
I think the main problem is that there is a strong connection between Canvas and nodes, every change in the canvas leads to a re-rendering of all the nodes. You can check this by dragging one node to another once with React Profiler started in the new 30 nodes story. This action causes ~ 30 re-renders without any visible changes on the screen.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

@@ -241,6 +240,14 @@ export const Node: FC<Partial<NodeProps>> = ({
}
});

useEffect(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide some context on this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When dragging, checkNodeLinkable is working for each node on the tree, with the condition "enteredNode?.id === properties.id" - only for the node, that is the drop target

}
})
}
onMouseEnter={event => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these need memo too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

onKeyDown = null,
onEnter = null,
onLeave = null
onClick = () => undefined,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be more ideal to leave these null or undefined and then do something like onClick.?()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@amcdnl
Copy link
Member

amcdnl commented Dec 6, 2021

Looks awesome overall, few questions but otherwise great!

setIsLinkable(checkNodeLinkable(properties, enteredNode, canLinkNode));
}

return () => setIsLinkable(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be returning a function, or just setIstLinkable(true)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsLinkable - boolean, it's callback for cleaning after node unmounted, so just a 'true'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to know!

@amcdnl amcdnl merged commit 4b1a1ba into reaviz:master Dec 6, 2021
@amcdnl
Copy link
Member

amcdnl commented Dec 6, 2021

@Nerevar123 - Released in 4.2.14!

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

Successfully merging this pull request may close these issues.

3 participants