Closed Bug 537362 Opened 15 years ago Closed 15 years ago

Optimize appendChild(lastChild)

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: codedread, Assigned: codedread)

Details

(Keywords: perf)

Attachments

(3 files)

I ran into the following scenario where I was appending the existing last child of an element to the element many times.  The result was that I was wasting a lot of JS cycles, but I also noticed that Mozilla ran orders of magnitudes slower than WebKit and still quite a bit slower than Opera.  This surprised me:

Chrome:  appended lastChild 2934013 times in 2s
Safari:  appended lastChild 2970559 times in 2s
Opera:   appended lastChild   93344 times in 2s
Firefox: appended lastChild   60257 times in 2s

Since this is a really simple optimization that doesn't hurt in the general case (when the new element is not already a child of the element being appended to) I thought I'd submit it.

Now I can build mozilla and run Firefox, but it's in Debug mode and I'm still learning how to do incremental builds, etc.  I'm not sure how to test this type of patch properly to observe the differences in performance.
I assume you'll attach the patch soon?
Assignee: nobody → codedread
OS: Mac OS X → All
Hardware: x86 → All
Sorry, I tried to read https://developer.mozilla.org/en/Mozilla_automated_testing but couldn't figure out how to run the tests.

P.S.  I checked WebKit's code and they do indeed have this optimization :)
Attachment #419660 - Flags: review?
Component: DOM → XSLT
QA Contact: general → xslt
Attachment #419660 - Flags: review? → review?(jonas)
Keywords: perf
Component: XSLT → DOM
QA Contact: xslt → general
So the patch is about xslt, but the testcase doesn't seem to have much to do with
xslt.
Or am I missing something here.
Attached file testcase
This shows that WebKit has a bug here. It optimizes out the mutation events in this case, even though DOM 3 Core clearly specifies that when appending node should be first removed from the old parent.
Yes, the patch was completely incorrect (did not deal with DOM), sorry about that.  Gavin set me straight in IRC.

As for the WebKit optimization being a bug, you are also right.
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → INVALID
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: