r/javascript • • Jan 15 '21

Svelte beats react for developer satisfaction in 2020

https://2020.stateofjs.com/en-US/technologies/front-end-frameworks/
346 Upvotes

231 comments sorted by

View all comments

Show parent comments

7

u/[deleted] Jan 16 '21 edited Jan 16 '21

React has a lot more overhead than svelte. This is from my limited understanding.

So take that with a grain of salt. But the virtual dom causes overhead. You have to do virtual dom diffing and then also make the changes to the real dom and sometimes one change to a div will require the whole component to rerender. So svelte being a compiler can build very clean code that doesn’t need to use virtual dom.

Here is a good read: https://svelte.dev/blog/virtual-dom-is-pure-overhead

Edit: grammar

7

u/qudat Jan 16 '21

React has rarely been the performance bottleneck on all of my prod apps and when it is there are ways to tune it.

1

u/[deleted] Jan 16 '21

Forsure, it’s rare you will need that performance but some apps do. I was just explaining that is what role svelte fills.

6

u/brainless_badger Jan 16 '21

Overhead of virtual DOM is greatly, and I mean greatly, overstated. Preact is nearly as fast as Svelte, and Inferno is faster - both are vdom libraries.

React's overhead comes from other places, like literally re-implementing event system.

3

u/ryan_solid Jan 16 '21 edited Jan 16 '21

How about an article based on actual measurement: https://medium.com/javascript-in-plain-english/javascript-frameworks-performance-comparison-2020-cd881ac21fce

Svelte is still component/control flow granular so it does do a nice chunk of re-evaluation, but it doesn't need in most cases to traverse down all its children. This makes it much faster than naive VDOM implementations. Precompiling DOM operations without running through what amounts to a giant switch statement for each part of the template also gives some nice gains.

2

u/[deleted] Jan 16 '21

Yeah you can see how fast svelte is but this article doesn’t show react vs able te the actual site has all frameworks. I couldn’t find the actual site but that allows you to pick and choose frameworks for comparison. This article still shows vanilla js vs svelte which is a good comparison.

3

u/ryan_solid Jan 16 '21

Not quite sure I follow. But all the major players are there including React/Svelte/Vue and full tables of 20 libs tested are included at the end of the article if you want to see all side by side. Although IMO the commentary is as valuable as the graphs. Mostly we get to see the raw technical performance with all the marketing hype shelved for a minute. The highest performing library is reactive no-VDOM, but 3 out of 5 of the fastest are VDOM.

First link of the article, all the code is in this repo: https://github.com/krausest/js-framework-benchmark

The table of latest results here I pulled from: https://krausest.github.io/js-framework-benchmark/2020/table_chrome_87.0.4280.66.html

1

u/[deleted] Jan 16 '21 edited Jan 16 '21

This is what I was trying to find. The article linked above just had screen shots but didn’t show all js frameworks.maybe I missed all of them together.

The virtual dom can be fast and has its place but still has overhead. Doesn’t mean it can’t be fast but you can get faster with something like svelte that is compiled and built to be performant.

Every tool has its use.

1

u/ryan_solid Jan 16 '21

Yeah it does show all the frameworks. And it does show Svelte being outperformed in every performance category and in size by a couple VDOM libraries. There are benefits to Svelte's approach but the meaningful impact of this overhead is variable. There are many types of overheads. Svelte has its own overhead/inefficiencies in other areas otherwise it would be front of the list. So while its fun to play at conceptual ideal, Svelte has similar although different conceptual walls based purely on its architecture.

2

u/[deleted] Jan 16 '21

Forsure this is definitely true. Every tool has various pros and cons. And some libraries that don’t use a virtual dom like angular are slow. So it definitely deends on the framework and isn’t all virtual dom VS dom.

0

u/[deleted] Jan 16 '21

[deleted]

1

u/[deleted] Jan 16 '21

I do know why, you can also read the article I posted. In most case the virtual dom is fast enough but there is still overhead to render everything at runtime

0

u/[deleted] Jan 16 '21

[deleted]

4

u/[deleted] Jan 16 '21

What are you talking about how does that have anything to do with the virtual dom?

Why would the dom have to make a request ? I’m honestly confused on what your trying to say.

Are you trying to say that if the page needs to change that static html would have to make multiple requests ? Where virtual dom does not ?

0

u/[deleted] Jan 16 '21

[deleted]

1

u/[deleted] Jan 16 '21 edited Jan 16 '21

We were talking about the dom vs virtual dom though which has nothing to do with routing. Seems like you don’t know what the DOM is or how the virtual dom works and are just saying stuff now.

Kind of embarrassing that you tried to call me out saying “do you even know why there is a virtual dom or do you assume more = bad” to then go on and say the virtual dom “it makes it so you don’t have to have multiple server request compared to a static html setup ”to show you don’t have the slightest clue what the dom is or how it works or even how the front end works for that matter. Then when I ask what you mean you say “client side vs server side routing”

You don’t have to request a route from the server each time you want to update the state or the ui even if you aren’t using vanilla js(I.e no virtual DOM). You can can make a change directly to the page with the DOM without having to request a new page from the server as you are suggesting, which again makes no sense to the context of the discussion above.

The virtual DOMs main purpose is not client side routing. It’s main purpose is to help abstract away dom manipulation. But the virtual dom still has to eventually use the real dom to make changes (I.e remove an item from a list since a user clicked a button).

I just think it’s funny for someone to go around accusing another person of not knowing what something is when they make it very clear they don’t have the slightest clue what the dom or virtual dom are. Maybe next time look something up if you are unsure or don’t know something before you make an aviation like that. You know...learn a little. It’s sure is better to learn something than to show your arrogance.

Here some resources:

Virtual DOM: https://reactjs.org/docs/faq-internals.html

DOM:

https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction

0

u/[deleted] Jan 16 '21

[deleted]

4

u/[deleted] Jan 16 '21

This is completely incorrect though. The virtual dom is not faster than the real dom. It’s an added layer used to interact with the dom.

Why you you update an entire page to change when piece while using the regular dom. There is no rule you have to do this. I can easily change one node of the dom (an html element) without change every other node.

Again the virtual dom has to use the real dom. It’s like you didn’t read anything I said or just have no clue what your talking about. It is embarrassing for you. Because everyone here that knows what the dom and virtual dom is and how they work can see you trying to make shit up to not seem like a fool for making your original comment but then you keep going further.

Anyways just next time don’t make a comment like that when you don’t really know how something works.

0

u/[deleted] Jan 16 '21

[deleted]

→ More replies (0)

2

u/m9dhatter Jan 16 '21

I think that programmers should really know the difference between “then” and “than” seeing that we use if-then-else statements all the time.

4

u/[deleted] Jan 16 '21 edited Jan 16 '21

I should but I do make that mistake all the time. Thanks for pointing that out.

I think for me it is the way I say it in my head. I hear the words being said in my head and I forget to make the difference between the two.

I hope to get better at it and really do appreciate you calling me out, hopefully will save me from looking like an idiot in front of someone important.

1

u/m9dhatter Jan 16 '21

I honestly just expected a quick down vote, and I don’t know how to deal with this reply. You’re welcome, I guess? 😂

2

u/[deleted] Jan 16 '21

Well it’s true. I made a mistake and I have trouble with mixing up then be than even knowing than is for comparisons. Something in my head. Anyways I need to be better at it and no spelling in general(I have sausage fingers when I type on my phone).

-1

u/MadCervantes Jan 16 '21

Petty

0

u/[deleted] Jan 16 '21 edited Jan 16 '21

Wrong area