New issue
Advanced search Search tips

Issue 814104 link

Starred by 3 users

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

append is slower than appendChild

Project Member Reported by hayato@chromium.org, Feb 21 2018

Issue description

As per the benchmark, https://jsperf.com/document-fragment-vs-appendchild/1, append is slower than appendChild.

- appendChild: 5,642 Ops/sec
- append: 4,845 Ops/sec


See also:
- https://dom.spec.whatwg.org/#dom-parentnode-append
- https://github.com/whatwg/dom/issues/433 for Standard.

Note that Blink has an optimization in a case of nodes.size == 1 so that DocumentFragment is not created.

https://cs.chromium.org/chromium/src/third_party/WebKit/Source/core/dom/Node.cpp?q=Node.cpp&sq=package:chromium&l=536

However, the benchmark does't use multiple arguments, so it might not matter.
 

Comment 1 by hayato@chromium.org, Feb 21 2018

Components: Blink>Bindings
Status: Assigned (was: Available)
I've investigated roughly. I've focused on only the use case of passing a single arg. A case of passing multiple args is out of scope here.

Since `append` can take multiple args, Blink always allocates a HeapVector for holding multiple args, even if a single div is passed actually, which can be a reason for the noticeable difference.

As an experiment, I've made other versions of |append|, A) |appendSingleNode| and B) |appendSingleNodeOrString| for comparison. Both can take only single parameter. See https://chromium-review.googlesource.com/c/chromium/src/+/927928

The benchmark result is:

https://jsperf.com/appendchild-vs-append2

- appendChild:              5,227 Ops/sec
- append:                   4,313 Ops/sec
- appendSingleNode:         5,448 Ops/sec
- appendSingleNodeOrString: 5,104 Ops/sec

The benchmark result is not stable, however, I can say append is always slowest in every runs.

Comment 2 by hayato@chromium.org, Feb 21 2018

Status: Available (was: Assigned)
Binding folks, if you have any ideas to avoid allocating HeapVector for a single arg, let us know that.
It probably wouldn't be too hard to map to a HeapVector with inline capacity (whatever we think is reasonable; maybe 4 or 8?).

Depending on what the call sites do, it might also be useful to make efficient move-constructing from a vector of different inline capacity possible.

Not clear to me whether append and other varargs IDL methods have substantial usage (after all, callers can already use appendChild).

Comment 4 by hayato@chromium.org, Feb 22 2018

> Not clear to me whether append and other varargs IDL methods have substantial usage (after all, callers can already use appendChild).

I'm not sure about each usage, however, this is a general issue of varagrs IDL methods, as you said.

Maybe we might want to change the title of this issue, or file a new issue so that people know that this might apply other varargs IDL methods widely.

Comment 5 by hayato@chromium.org, Feb 22 2018

I think the difference can be detected only by micro benchmarks.
It is unlikely that real web sites can notice the difference.

This is P3 issue for us, I think.
Components: -Blink>DOM

Sign in to add a comment