[whatwg/dom] prepend/append are inefficient compared to doing it yourself (#433)

(1)
```js
let nodes = [...1000 nodes];
for (let i = 0; i < length; ++i)
  parent.appendChild(nodes[i]);
```

This is N, where N is the length of nodes.

vs

(2)
```
let nodes = [...1000 nodes];
parent.append(...nodes);
```

The latter allocates a document fragment, inserts every node into the fragment, then appends that fragment which removes every node from the fragment and does the work that would have been done in (1).

This is 3N (append to fragment, remove from fragment, insert into page), and double the number of insertions, plus a bunch of removals which the former didn't do at all.

While in theory you could probably come up with a way to skip the fragment and hope no future spec every makes insertion observable, it's actually required in the exception case because the fragment is left as the parent node of the converted nodes.

```
let e = document.createElement("div")
try {
  document.body.append(e, document);
} catch (e) { }
e.parentNode // => #document-fragment
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/433

Received on Saturday, 25 March 2017 02:14:13 UTC