Bug 160728 - Optimization in Node::appendChild() is not spec-compliant
Summary: Optimization in Node::appendChild() is not spec-compliant
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: WebExposed
Depends on:
Blocks:
 
Reported: 2016-08-09 19:54 PDT by Chris Dumez
Modified: 2016-08-09 20:49 PDT (History)
5 users (show)

See Also:


Attachments
Patch (15.96 KB, patch)
2016-08-09 20:16 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (15.97 KB, patch)
2016-08-09 20:20 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2016-08-09 19:54:36 PDT
We have an optimization in Node::appendChild() that avoid doing any work if the node to be appended is already the last child. This optimization is not spec-compliant:
- https://dom.spec.whatwg.org/#dom-node-appendchild

The issue is that this is observable via DOM Mutation observers / listeners or DOM ranges.
Comment 1 Chris Dumez 2016-08-09 20:16:47 PDT
Created attachment 285709 [details]
Patch
Comment 2 Ryosuke Niwa 2016-08-09 20:18:55 PDT
Comment on attachment 285709 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=285709&action=review

> Source/WebCore/ChangeLog:20
> +        common to call parent.appendChild(parent.lastChild). It turns out to
> +        regress the performance of things we care about though, we could fall
> +        back to do the optimization only when it is not observable.

You mean if it turns out to regress?  If we know for sure that this regresses the perf, we need to change the spec instead.
Comment 3 Chris Dumez 2016-08-09 20:20:05 PDT
Created attachment 285710 [details]
Patch
Comment 4 Chris Dumez 2016-08-09 20:20:36 PDT
(In reply to comment #2)
> Comment on attachment 285709 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=285709&action=review
> 
> > Source/WebCore/ChangeLog:20
> > +        common to call parent.appendChild(parent.lastChild). It turns out to
> > +        regress the performance of things we care about though, we could fall
> > +        back to do the optimization only when it is not observable.
> 
> You mean if it turns out to regress?  If we know for sure that this
> regresses the perf, we need to change the spec instead.

*If* it turns out. I indeed forgot a word :) This is fixed in the latest iteration.
Comment 5 Ryosuke Niwa 2016-08-09 20:27:11 PDT
Comment on attachment 285710 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=285710&action=review

> LayoutTests/fast/dom/Node/appendChild-no-op-mutationobserver-expected.txt:1
> +Tests that calls of appendChild() lead to mutation events even if they are no-ops.

In the future, we should probably write these tests using testharness.js so that we can upstream to W3C test suite.
Comment 6 WebKit Commit Bot 2016-08-09 20:49:27 PDT
Comment on attachment 285710 [details]
Patch

Clearing flags on attachment: 285710

Committed r204322: <http://trac.webkit.org/changeset/204322>
Comment 7 WebKit Commit Bot 2016-08-09 20:49:31 PDT
All reviewed patches have been landed.  Closing bug.