I came across some interesting discussions around the performance of API recursive traversal methods like
findAll, and I wanted to dig into deeper to figure out the best workaround given their behavior and the specific needs of our plugin.
In summary, it seems like traversal slows down significantly when encountering hidden layers, because Figma doesn’t instantiate invisible nested layers (since before variants released, files often contained tons of hidden layers as a workaround which quickly maxed out memory).
Here are the links to the discussions around this:
- Estimating the size of the search tree - #4 by Gleb
I’m assuming that means the hidden layers are stored as a reference and a slower lookup occurs when you access them in any way.
Our plugin doesn’t need to work with hidden layers, so I am wondering what the best workaround would be in this case. Is there additional info from Figma folks regarding how the uninstantiated hidden layers work under the hood that might be helpful?
Since Rudi at Figma (see last link above) said those layers aren’t instantiated at all, I’m thinking the hidden layers are stored as a reference and there’s no way to avoid the slowdown when using
findAll on a node containing hidden layers, and the fastest workaround would be a custom recursive method that only handles a node and continues to recurse through its children if visible? Seems I’d still get the slowdown on the top hidden ancestor node, but I’d at least be able to avoid recursing through its children to skip all nested layers hidden within.
Does that sound reasonable to anyone here who has similar circumstances (no need to work with hidden layers anyway) and has experimented with this?