5 ms·
Why not just double-buffering the DOM? That'd be much simpler. Mutate your DOM all you want, then swap it in when it's ready.
by Kenji 8y ago
Why not just double-buffering the DOM? That'd be much simpler. Mutate your DOM all you want, then swap it in when it's ready.
- a_t48 8y agoPossibly race conditions between scripts which see different versions of the DOM.
- spankalee 8y agoThis allows the browser to delay all style, layout, and paint work on attached DOM, and then also spread that work across multiple frames during a commit, reducing jank for the unlocked portions of the page. If you synchronously swap a large portion of DOM, style, layout, and paint will likely blow your frame budget.
- ballenf 8y agoEither I don't understand double buffering very well (not unlikely) or I don't know what you mean by "frame budget". Wouldn't swapping one buffer for the other be faster than most or all of the computations going into calculating that background buffer and easily doable in a single frame? What am I missing?
- deleted 8y ago[deleted]
- dfox 8y agoNormal double-buffering involves doing something trivial at the moment of buffer-swap, like changing pointer or at most doing large-ish memory copy. Double buffering DOM would either not solve the problem (in the case of doing the layout computations in background and then swapping already layed out DOM) or would involve doing all the layout computations at once when the swap happens (with the implication of this being mostly equivalent to loading new page and thus slow and in many cases too slow to happen at 30, 60 or whatever Hz)
- unilynx 8y agoWe can already do that: clone first and replaceChild afterwards. It breaks already attached event handlers, undo buffers for input elements, and any existing references you have to DOM nodes.
- pjc50 8y agoThe DOM isn't a buffer, it's a tree; doing a deep copy would be an expensive operation incurring lots of little allocations.
- derefr 8y agoThat's essentially what is already done, without the browser's assistance, with "virtual DOM"-style libraries. The point of this work is to obviate the need for a virtual DOM.
- stephengillie 8y agoGamers know triple-buffering is obviously superior.
- DonHopkins 8y agoMy buffers go to eleven.
- tinus_hn 8y agoWhat is the difference? This allows you to mutate the DOM all you want and then have it redrawn when it’s ready.