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

perf: Make index of Node readonly to prevent potential perf problem #1777

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

luowenxing
Copy link

Make index of Node readonly to prevent potential remove child with complexity o(n^2)

Note that Konva.Container#removeChildren function comment with these line

reset parent to prevent many _setChildrenIndices calls

That means without reset the parent, Konva.Node#remove would call _setChildrenIndice which will take into extra o(n^2) complexity. It works in this case but failed in other case such as call remove node in a certain loop, which offen ocurrs in increasing draw visible node and decreasing destory invisible node in current viewport.

Thus replace the index property with readonly index is a better way to prevent the unexpected complextiy by frequent operation of a Konva Node.

@lavrton
Copy link
Member

lavrton commented Jun 12, 2024

Do you have a specific sample/demo where it gives performance boost?
Currently, it fails tests.

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.

None yet

2 participants