Bug 1846389 [wpt PR 41265] - Add append_to argument to Clone() to avoid extra Inserte...
commit4413a3242d9615829aeba5b9e01fc098b199a79e
authorMason Freed <masonf@chromium.org>
Wed, 9 Aug 2023 10:50:41 +0000 (9 10:50 +0000)
committermoz-wptsync-bot <wptsync@mozilla.com>
Thu, 10 Aug 2023 14:59:02 +0000 (10 14:59 +0000)
tree75b043ecaa638197f0d9ac110a7d8d0d70c5e3fa
parent34422fd5e3d6610309950a5b79835f19f87d8923
Bug 1846389 [wpt PR 41265] - Add append_to argument to Clone() to avoid extra InsertedInto calls, a=testonly

Automatic update from web-platform-tests
Add append_to argument to Clone() to avoid extra InsertedInto calls

Because of the order of operations for Clone(), previous to this CL,
the typical sequence would be:

 1. Clone the element
 2. Clone the children of the element (recursing to step #1).
 3. AppendChild() each cloned child to its parent cloned element.
 4. (in the caller of Clone) AppendChild the cloned element to its
    eventual parent.

Because each AppendChild triggers a call to Node::InsertedInto() for
*all descendants of the appended element* [1], the fact that the tree
is constructed bottom-up (leaf nodes first) means that InsertedInto()
is called N^2 times, where N is the depth of the cloned tree.

Because clone-and-append is a very common pattern, this CL adds an
`append_to` argument to `Clone()`, which appends to the parent before
appending the children.

This CL also adds a perf test for this scenario (cloning a deep tree).
Locally, on a debug build, this test gives 0.13 runs/s before this CL,
and 0.40 runs/s after, for a 3.1X speedup.

[1] https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/dom/container_node.cc;l=1006;drc=5d60017dba57e86d477634812e1340127734f8a7

Bug: 1453291
Change-Id: Icdd75c45aa5ecc4fe8bb5d1ff0b7a2b27bec2171
Cq-Do-Not-Cancel-Tryjobs: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4728983
Reviewed-by: David Baron <dbaron@chromium.org>
Commit-Queue: David Baron <dbaron@chromium.org>
Auto-Submit: Mason Freed <masonf@chromium.org>
Commit-Queue: Mason Freed <masonf@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1177922}

--

wpt-commits: d73d9dc406f6eaf5cb52facc67f7884587b1dfac
wpt-pr: 41265
testing/web-platform/tests/custom-elements/form-associated/form-disabled-callback.html