Can someone explain to me why virtual DOM is faster than DOM implementations of browsers?
Actually changing the DOM has a lot of implications. Recalculating CSS, layout, possible side effects that generate events, repainting, etc, etc. It's a lot of work to go through for an intermediate state that may not even last long enough to be visible to the user. Buffering and batching those changes can save a lot of that effort. I suppose in theory the browser could optimize this as well but in practice it seems…
Netflix Likes React
41–50 of 60 posts
Re: Netflix Likes React
#42Earlier quoted context omitted.
Actually changing the DOM has a lot of implications. Recalculating CSS, layout, possible side effects that generate events, repainting, etc, etc. It's a lot of work to go through for an intermediate state that may not even last long enough to be visible to the user. Buffering and batching those changes can save a lot of that effort. I suppose in theory the browser could optimize this as well but in practice it seems…
Yes but WHY don't the browser makers optimize for what seems to be this very common use case? Why does a third party library outperform them?
Re: Netflix Likes React
#43Earlier quoted context omitted.
Boy, people never want to accept this. On my team, designers write the HTML. They own markup & styling. Designers don't want to dig through JS files to change markup, but an even bigger problem is that it's only kinda-sorta markup. For example, if you want to set a class on an element in JSX, it's not class="", it's className="". Because class is a reserved word in JS. How many other little warts like that are there,…
"How are they supposed to remember stuff like that?" Designers are never given enough credit. If they can handle all of the insanities of CSS (and various preprocessors), this will seem like cake. Its just a single `render` method, generally living at the top or the bottom of a file; nothing complex. Additionally, you stub out your static html markup first -- just like in a template -- and then you add interactivity.…
A wrinkle I did not mention is that we are in the process of transitioning how we do views. The new stuff is Ractive, but the old stuff is another library whose templates are also straight HTML. So using JSX would not only incur the aforementioned problems but also "wait, this is JSX so I should use this attribute name, and this is HTML so I should use this one." It just sounds shitty to me. And to them.
The situation is not designers can't handle it, the situation is they shouldn't have to deal with that kind of crap.
Re: Netflix Likes React
#44Re: Netflix Likes React
#45Earlier quoted context omitted.
Yes but WHY don't the browser makers optimize for what seems to be this very common use case? Why does a third party library outperform them?
Because when your code changes DOM, browser does not know whether you are going to stop at it for now, or do something else, so it has to re-render. In React you explicitly request application of virtual DOM changes to real DOM once you are done.
Re: Netflix Likes React
#46Can someone explain to me why virtual DOM is faster than DOM implementations of browsers?
More specific details here: http://facebook.github.io/react/docs/reconciliation.html
Re: Netflix Likes React
#47Earlier quoted context omitted.
React has a better chance because it is a micro framework or component or just the V like you mentioned. Typical evolution of new tech is monolithic to micro, frameworks to components/modules/libraries. In the end micro frameworks or libraries allow more flexibility to change over time. Always bet on the micro frameworks and libraries, they can be swapped more easily and typically don't create blocks in overall archi…
React is quite large in terms of lines-of-code. I would refer to it as a mili-framework instead of a micro one :)
Re: Netflix Likes React
#48Re: Netflix Likes React
#49Earlier quoted context omitted.
I am fairly certain that Ractive templates are similar to JSX in terms of overhead. If you don't like compiling JSX you can run it with the JSX client compiler at the cost of compiling it on every client. Ractive templates are parsed in JS just like JSX, which is why you have ractive compilers like this https://github.com/ractivejs/rv
I think the difference the OP mentioned is that Ractive templates are mustache-formatted strings, and can be stored in external files. So you have a JS file and a template file, not the combination of both you find in React.
Re: Netflix Likes React
#50Earlier quoted context omitted.
Yes but WHY don't the browser makers optimize for what seems to be this very common use case? Why does a third party library outperform them?
Because when your code changes DOM, browser does not know whether you are going to stop at it for now, or do something else, so it has to re-render. In React you explicitly request application of virtual DOM changes to real DOM once you are done.
Something like this maybe?
batchDomChanges(); ... dom changes here ... flushDomChanges();