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

Splice.Apply causes “Maximum call stack size exceeded” when there is 170k+ nodes under one node #51

Open
YeskaNova opened this issue Sep 21, 2019 · 0 comments

Comments

@YeskaNova
Copy link

I have a node which is loaded from the server, it loads 170k+ other nodes under it. An exception is raised in all Array.splice.apply calls in the code :

parentNode.children.splice.apply(parentNode.children, [index, 0].concat(newNodes));
...
this.nodes.splice.apply(this.nodes, [parentOffset + 1, deleteCount].concat(nodes));
this.rows.splice.apply(this.rows, [parentOffset + 1, deleteCount].concat(rows));
...
this.nodes.splice.apply(this.nodes, [nodeIndex + 1, 0].concat(nodes));
this.rows.splice.apply(this.rows, [nodeIndex + 1, 0].concat(rows));

The exception is “Maximum call stack size exceeded” and it's discussed here : https://stackoverflow.com/questions/21679300/array-unshift-invoked-using-apply-causes-maximum-call-stack-size-exceeded

I have soved it by creating a new method to do the splice in chunks :

function spliceApply(t,a,b,c)
{
for (var i = Math.floor(c.length / 10000); i>=0; --i)
t.splice.apply(t,[a,b].concat(c.slice(i*10000,(i+1)*10000)));
}

and transformed for example : parentNode.children.splice.apply(parentNode.children, [index, 0].concat(newNodes)) to spliceApply(parentNode.children,index,0,newNodes);

I haven't tested the code intensively but it works, hope you can fix it.

Thank you

asheshv added a commit to asheshv/infinite-tree that referenced this issue Dec 12, 2019
'Array.prototype.splice', which results into an error -
"Maximum call stack size exceeded" when working with very big arrays.

Reported By: https://github.com/YeskaNova
Issue cheton#51
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 a pull request may close this issue.

1 participant