javascript - Svelte multiple small components vs regular html elements - Stack Overflow

Does it affect performance having svelte components instead of regular HTML elements, for small things

Does it affect performance having svelte components instead of regular HTML elements, for small things like buttons, links etc?

Wrapping these elements in a svelte component would make it more convenient in code, but if it adds a lot of overhead then it may not be worth it.

Does it affect performance having svelte components instead of regular HTML elements, for small things like buttons, links etc?

Wrapping these elements in a svelte component would make it more convenient in code, but if it adds a lot of overhead then it may not be worth it.

Share Improve this question asked Mar 26 at 18:58 AlexAlex 66.1k185 gold badges459 silver badges651 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

There are two things that cause some overhead here:

  • The general Svelte runtime (managing reactivity, effects, rendering)
  • The generated component code

If you are using client-side functionality of Svelte at all, the runtime has to be loaded. The relative cost of this goes down with the number of component definitions since the runtime is shared.

The overhead for the component code also amortizes with the number of component instances, since they all share the same definition. So if you only have one or very few instances, it might make a noticeable difference in the bundle sizes but for any sufficiently complex application, I would not worry about this.

The code of simple wrapper components will share similarities which also helps if the code is transferred gzipped.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744131244a4559853.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信