Recursive Components vs Snippits. Which is more performant? #17260
Replies: 1 comment
|
Both versions are valid, and for this tree the complexity is essentially the same: each visible node is visited once, so rendering is O(number of rendered nodes). Passing node.children down is not, by itself, an expensive form of prop drilling. The practical difference is the abstraction boundary:
So I would choose the snippet for this exact example if it remains presentational. Choose the recursive component if each directory needs its own state (expanded state, subscriptions, actions, context) or if you want to reuse/test that level independently. I would not expect prop passing to be the deciding performance factor unless profiling shows it is. A few details matter more:
For a small or medium tree, use the clearer version and measure before optimizing. |
Uh oh!
There was an error while loading. Please reload this page.
so, i am building a file tree component in svelte which takes an array of objects whith this data structure
i built a fully working minimal file tree compoenent with recursive component this (simplified)
and also with snippits
now, some things that i didn't include in the code is that,
does that affect performace, compared to not prop driling and using snippits?
i wonder which one is more performant?
All reactions