no it doesn't. operations on a VDOM are much much faster than operations on the actual DOM. Also, it's not "re-applying the same changes again", the VDOM is used exactly for diffing the rendered subtree to the current state so that the number of actual, costly DOM update operations can be minimized. VDOM operations are as cheap as they get.
Svelte is nice, sure, but for most real world use-cases, it's not really that much faster than React.
Exactly. 99% of the time you run into performance issues with vue or react, you made a mistake. You would have make many thousands changes every second to hit the limits of the vdom approach.
DOM is only slow if you do updates across multiple ticks instead of pre-compiling and batching everything together. React fixes problems for bad developers who don't understand browser's inner workings and write crappy code.
Angular is doing it with zones and template compilation. Svelte is using pre-compiled templates as well.
The problem is not that DOM is slow, but how you interact with it. You still have to alter it when using React, there's no way around it, so saying that virtual DOM is fast is completely irrelevant.
What React is doing is that it applies your changes to virtual DOM and at the end of a cycle diffs it to the real deal and then only touches parts which should be changed.
On the other hand Angular compiles special code which tracks data changes bound to each template and updates DOM directly. This approach also changes only those parts of DOM which need to be changed. And zones help to track when these data updates happen. Then at the end of a tick, compiled templates do their job and everyone's happy.
The difference here is that everything in Angular is static and pre-compiled and everything is data driven. React creates a new dynamic structure instead and that always has performance penalty. But static nature has its own issues of course, for example, you can't create new components in run time - they all must be compiled offline and served as part of application.
12
u/csorfab Jan 16 '21
no it doesn't. operations on a VDOM are much much faster than operations on the actual DOM. Also, it's not "re-applying the same changes again", the VDOM is used exactly for diffing the rendered subtree to the current state so that the number of actual, costly DOM update operations can be minimized. VDOM operations are as cheap as they get.
Svelte is nice, sure, but for most real world use-cases, it's not really that much faster than React.