Skip to main content
Question

Are the functions Node.width / height O(1)?


Vincent_Huss

Hi !

I would like to know when i do node.width or node.height,
if within the Figma API, the retrieval of this information is O(1) or more.
in other words, is it precalculated, and available as a data to be just returned ?
or does this triggers some calculations involving loops over the children (and potentially recursive)

and if it does, is it internally cached to avoid recalculating it twice ? (if nothing was written in between)

thanks in advance for the insight !

This topic has been closed for replies.

4 replies

y_toku
Figmate
  • Community Support
  • 2545 replies
  • January 24, 2024

H there,

Thanks for reaching out. I’m checking with our internal team, and I’ll get back to you if there is anything I can share with you!

Thanks,
Toku


y_toku
Figmate
  • Community Support
  • 2545 replies
  • January 25, 2024

Hi there,

As I checked with our internal team, we don’t do any recursive traversal to calculate the size. Why not always O(1)? When interacting with a node object, sometimes we need to make sure that that the node is in a “clean” state before reading its properties.

I hope it helps. We will keep improving with your feedback!

Thanks,
Toku


Vincent_Huss
  • Author
  • Active Member
  • 29 replies
  • February 11, 2024

Thank you very much for your answer and sorry for the super late reply,

so can i assume that if querying the width/height of a specific node 2 times in a row, the 2nd time will be O(1), it’s only if the user (designer) modifies the node or a child that it gets labeled as “dirty” and triggers some recalculations


y_toku
Figmate
  • Community Support
  • 2545 replies
  • February 13, 2024

@Vincent_Huss thanks for the reply! Yes, you can assume that getting the width/height should be O(1) most of the time.

I hope it helps!

Thanks,
Toku


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings