-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 processing when nodes have large numbers of children #2080
Comments
3 seconds is good compared to
nearly 30 minutes I just got |
I've been working on a version that addresses some of these performance issues. The short term solution I came up with is to modify The only way I see that this could get weird is if an element detaches its siblings, but as far as I can see this isn't happening.
|
@johnkenny54 - looks good to me! It should work better than what I was thinking, too, since it doesn't require new properties. What do you think about having It'd be nice if I did start changing our custom plugins to traverse children and process them in bulk, but it doesn't seem quite as obvious to plugin authors to do it that way for a first implementation. |
My personal preference is to deprecate |
I see where you're coming from. I'd just note though that at the moment the default is for plugins to have performance problems at scale (including the built-in ones), and it takes an extra step for people to realize and improve the situation (as for my case), so I'm interested in ways to make the default path have better performance. |
Problem
I have an SVG with ~25k children under the same parent, and it takes ~9 seconds to optimize. Unfortunately these sorts of SVGs are not entirely unusual for my use case :( Notably though, with a small change I reduced the time to ~3 seconds.
Suggested solution
You're probably aware of the two operations that turn the overall traversal into O(N2):
detachNodeFromParent()
(which recreates the array while removing just one element) and theif (parentNode.children.includes(node))
line in xast.js. I addressed these in a local change by deferring the node removals using a set. The changes I made were hardly revolutionary, but I'm posting them below for clarity. The downside of course is that they'd technically introduce an incompatibility with plugins that remove siblings without callingdetachNodeFromParent
.Maybe something like this is worth including in a future major change though, one where the release could announce the small difference in behavior?
Workaround
I'm using this deferred removal in some custom plugins to speed them up (just adding an apply step in the exit callback). I also tried working around the issue by splitting the ~25k siblings into subgroups as a first step, but the grouping causes problems with some other parsing we do later down the line, so it's not ideal.
Related
Note this is a similar issue to #1969, so feel free to merge if you like, but I'm initially posting it here for visibility so it doesn't just disappear as a comment.
The text was updated successfully, but these errors were encountered: