I came across some interesting discussions around the performance of API recursive traversal methods like findOne
and findAll
, and I wanted to dig into deeper to figure out the best workaround given their behavior and the specific needs of our plugin.
Background:
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
- https://twitter.com/zyumbik/status/1356604748821053443
- https://twitter.com/digitalfreepen/status/1356662733135994881?s=20
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.
My question:
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 findOne
/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?