4 ms·
My understanding is that DOM manipulation and queries will always be far far slower than the logical equivalent in JavaScript. Does "thousands of times faster"
by Waterluvian 8y ago
My understanding is that DOM manipulation and queries will always be far far slower than the logical equivalent in JavaScript. Does "thousands of times faster" challenge that?
Ie. React's virtual DOM is a phenomenal idea because it greatly reduces actual DOM interaction. Is it not really saving us much in Firefox?
- austincheney 8y agoThe DOM is a structured API to markup (HTML/XML). That means DOM instructions are access to something outside the language. Leaving the language, for any reason, is slower than executing within the language. That said the execution speed of DOM instructions is orthogonal to the execution speed of JavaScript alone. > Is it not really saving us much in Firefox? The DOM is the standard technology the browsers use to communicate from JavaScript to markup. QuerySelectors are strings, so they have to be parsed into DOM instructions by the browser using a native code engine. Since the DOM is a well defined standard and it is the standard that all browsers use DOM instruction performance can be directly compared between the different browsers.
- bzbarsky 8y ago> DOM manipulation and queries will always be far far slower than the logical equivalent in JavaScript. That really depends on what you're doing. Reimplementing querySelector in JavaScript (even if you do it on top of JS-only node representations, not on actual nodes) is likely to be slower than the built-in version, for example. If you're doing a "modify-read-modify-read" cycle, then things are different because the contract is different: the DOM promises that reads will see all modifications, while some of the other systems built around it don't. > Is it not really saving us much in Firefox? It really depends on the shape of your workload. There are various cases where React's virtual DOM is pure overhead and just makes things slower. [Disclaimer: I work on a browser rendering engine, and have done a fair amount of performance work, so I may have my biases about what I see in profiles.]