Bug 103696 - Fast path isDescendantOf for nodes in different documents
Summary: Fast path isDescendantOf for nodes in different documents
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Elliott Sprehn
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-29 17:50 PST by Elliott Sprehn
Modified: 2022-08-14 12:42 PDT (History)
6 users (show)

See Also:


Attachments
Patch (1.43 KB, patch)
2012-11-29 17:52 PST, Elliott Sprehn
morrita: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Elliott Sprehn 2012-11-29 17:50:38 PST
Fast path isDescendantOf for nodes in different documents
Comment 1 Elliott Sprehn 2012-11-29 17:52:57 PST
Created attachment 176868 [details]
Patch
Comment 2 Hajime Morrita 2012-11-29 19:27:43 PST
Comment on attachment 176868 [details]
Patch

How often is this help?
It looks interacting nodes are usually living in the same document.
In such case this check just adds an extra check.
Comment 3 Elliott Sprehn 2012-11-29 20:07:26 PST
(In reply to comment #2)
> (From update of attachment 176868 [details])
> How often is this help?
> It looks interacting nodes are usually living in the same document.
> In such case this check just adds an extra check.

This happens whenever you move a node from one iframe to another, or the parent document. In those cases we traverse the ancestors when there's no reason to.

Looking at places where we use isDescendantOf() it's almost always the same document except in checkAddChild() or checkReplaceChild() where they could be in different documents. The inDocument() check we already do here is similarly as rare. Nodes are almost always already in the document when we do isDesendantOf except during appendChild() and removeChild().

So if this is a regression then we probably shouldn't do the inDocument() check except for appendChild() and removeChild().
Comment 4 Hajime Morrita 2012-11-29 23:16:38 PST
Comment on attachment 176868 [details]
Patch

OK, let's land and see how this goes. Before landing, please check Dromaeo/dom-modify to ensure that this doesn't impact non-iframe case much.
Comment 5 Ahmad Saleem 2022-08-02 04:51:05 PDT
I don't see this landing in Webkit source (from Github) despite being r+ and mentioning about landing in Comment 04.

I am not sure whether this patch is applicable today or not but just wanted to leave quick link here:

https://github.com/WebKit/WebKit/blob/main/Source/WebCore/dom/Node.cpp#L1025

Appreciate if someone can mark this bug accordingly. Thanks!
Comment 6 Ryosuke Niwa 2022-08-02 09:13:31 PDT
This is a won't fix at this point.
Comment 7 Elliott Sprehn 2022-08-02 17:48:49 PDT
Fwiw this perf cliff still exists. Moving nodes between two documents walks up the tree resulting in depth of tree work. If you remove from one document first it avoids that by taking the isConnected fast path because we check the ancestors before removal.

So like:

deepNode.remove()
otherDocNode.appendChild(deepNode)

Should be faster than

otherDocNode.appendChild(deepNode)

The debate was always if one extra branch in the common case (maybe with an UNLIKELY) is worse to guard against the cliff.