Virtual DOM is pure overhead (2018)
11–20 of 337 posts
Re: Virtual DOM is pure overhead (2018)
#12Re: Virtual DOM is pure overhead (2018)
#13Inferno.js uses VDOM https://github.com/infernojs/inferno and is faster than Svelte according to these benchmarks https://krausest.github.io/js-framework-benchmark/2023/table... . Sooo, VDOM can improve performance?
This article doesn't really argue against that. They say the VDOM is a "means to an end" and is "generally good enough".
The thrust of the article seems to be that a virtual DOM isn't a guarantee of performance. Rather it's just one solution that can be pretty fast. Svelte happens to take a different approach which is also pretty fast.
Re: Virtual DOM is pure overhead (2018)
#14Re: Virtual DOM is pure overhead (2018)
#15Svelte is great. React is great. X, Y and Z are also great. And you know what they all share as well? Speed. They are all fast . Definitely fast enough for 99% of all uses cases if not more. The benchmarks they all provide are just benchmarks. I treat them like I treat car range reports by the car makers. I personally use react because I know it well, and it allows me super speedy development cycle once all the base…
Re: Virtual DOM is pure overhead (2018)
#16Re: Virtual DOM is pure overhead (2018)
#17So the vdom approach of processing all the static parts of a template during a diff is just extremely wasteful, especially for fairly common cases like conditionally rendering a node before some static content.
Ideally you already know what changed, and can just update the parts of the template that depend on it. In JS that typically requires a compiler, complexity, and custom semantics (like Solid). But you can get very, very close to that ideal with plain JS syntax and semantics by capturing the static strings and the dynamic values separately then only comparing the dynamic values on updates.
This is what we do with lit-html and why I think tagged template literals are nearly perfect for HTML templates.
With tagged template literals, an expression like:
html`Hello ${name}!`
is passed to the `html` tag function as an array of strings `['Hello ', '!']` and an array of values: `[name]`, and the strings array is the same every time you evaluate the expression, so you can compare it against the previous template and only update the values in the DOM if it's the same.It's a really efficient way to render and update DOM with a pretty simple conceptual model that requires no compiler at all - it's all runtime. I think it's straightforward and powerful enough to be standardized at some point too.
Re: Virtual DOM is pure overhead (2018)
#18Re: Virtual DOM is pure overhead (2018)
#19So is the JS runtime. So why don't we just write apps in raw WASM?
Anyway, another idea is to ditch the entire DOM and render on the canvas.