Skip to content

re: Svelte Needs A Virtual DOM VIEW POST


Hey, I just created a small snippet to explain better the approach Svelte uses to update the dom:

That's a Svelte version, you can check using devtools:

That's a vanilla version to have a big overview of how Svelte schedule the updates:

You can see that it doesn't update the dom multiple times!

The main difference with React will be when the concurrent mode is released. React will have a way to "stop and continue" the rendering process between the cycles/ticks.

But, actually Svelte uses a completely different approach, and I'm not saying it's better or worst. It's just different. I really like React and I'm impressed with Rich Harris (and the community) work on Svelte. I'm pretty sure we have space for both.

The other thing is: actually, if we run, e.g:

(a, b) => a + b


() => {}

Which one will run faster?
So, if you remove the code, of course it will be faster, and less code, less bugs.

Of course, it's not the only way you can improve the speed of your app, but it's the only one that it's 100% guaranteed it will do.

And about React, well, I think they are thinking too much of how to make the things faster, run smooth, but, maybe would be good to think like Rich Harris? Instead of trying new ways to speed up, just remove the code, make ReactDOM bundle smaller, maybe tree-shakable, less boilerplate on the events layer, or even, invest on an ahead of time compilation.

So, my 2cents: Svelte don't need a virtual DOM. :)

Some useful links about the topic:
// some links talking about the virtual dom (opinionated maybe? go for your own risk, haha)

// real world implementation in svelte an react+redux

// compile time computations to js to minimize the work in runtime

// build react to html in compile time


Thanks for the comment.

I didn't mean one line update in the latter example. It's supposed to be this

let number = 1;
let displayNumber = number

So, the empty comparison doesn't hold good.

Trying new ways to speed up is good. Svelte is an awesome framework. But react is a lot mature and handles more scenarios to optimize performance.

I could see layout taking a lot more time in Svelte which is also a major concern.

I will also make more study on the same and update the same on data basis next time.


React does not handle more scenarios.

React exposes more hooks or states so you can inform it how to be more performant.

ShouldComponentUpdate, ShouldComponentMount, or what have you. It’s been a while.

The reality is, you should not need those, if it was not for a systemic performance issue. Look at 2016 articles of optimizing React before react 16. Sure it got better since, but so has our devices, internet and browsers.

Run that code in a nexus 5 with a 3G connection in Puerto Rico inside a Facebook webview.

Sorry to differ it does handle more scenarios. One of them is, it compares the dom and then updates. A read is much faster than the write as write has to alter the entire dom tree.

Your missing my point.

It does not matter the library does more work. What matters is the speed for the user. It’s great they do that. But you are downloading a much larger bundle size to get that benefit. And in 95 percent of SPA sites, it’s not needed.

When we talk about performance, we have a habit of saying “this is faster” or “this updates more elements” or “it’s smarter about how it does it”.

The reality is, touching the DOM is not bad. And in most cases the added benefit of a virtual DOM is not felt. And Svelte performance actually shows its faster without the virtual DOM than react is with it.

This will keep going back and forth as both libraries keep optimizing. The big thing here, is to understand that a virtual dom is not a requirement for a fast experience. And the cost of it, is a larger bundle size.

When you remove the developer experience, and your look at the performance realistically (perception and what is needed) your left with bundle size. And react can’t touch svelte on that.

The whole point is updating the Dom is 100% slower. Please have a look at the results here,

Ok at this point your not really reading or consuming other viewpoints.

Tests I have seen that are not yours have shown otherwise, but please read everything else I said about performance.

I would also say the same, you are not reading all the points that I say.

Yes svelte is a lot better for not complex apps.

If you say 95% of the websites don't need that, we must see most percent of websites are wordpress without a thought on optimization.

Anyway, please have a look at this.

code of conduct - report abuse