Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Touching DOM is an expensive operation. Think about the virtual DOM as a double buffer.


You don't need a VDOM to use a buffer to batch changes. A VDOM is a buffer that comes with a huge amount of overhead vs an ordinary sequential buffer of DOM manipulation commands.

VDOM is an optimization that allowed react to be fast enough to work, it can never be faster than direct dom manipulation.


Yes. You are right. Vdom is useless.


VDOM isn't useless. It's basically an optimized immutability helper. React wouldn't have been feasible without it.

But mutating the data directly is always going to be faster.

If you want to operate at a level of abstraction where you can ignore mutability and say rerender an entire huge ul every-time a single li changes, then using a VDOM to calculate the diff so you can only replace the single li is going to be faster than replacing the entire ul directly in the DOM. In many cases this is fast enough and so you get to program at a that higher level of abstraction.

However, if you have code that just directly replaces the innerHTML in the single li that changed, the VDOM can never be faster than that. Because it has to do that as well as calculate the diff to find which li it should change.

In essence Svelte just runs more of its abstraction optimization techniques at compile time instead of at runtime.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: