Bug 6718 - deep appendChild is too slow! (Safari wins on all but one JavaScript microbenchmark)
Summary: deep appendChild is too slow! (Safari wins on all but one JavaScript microbe...
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 420+
Hardware: Mac OS X 10.4
: P3 Normal
Assignee: Nobody
URL: http://idanso.dyndns.org/maps/jsbench/
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-22 15:10 PST by Eric Seidel (no email)
Modified: 2019-02-06 09:03 PST (History)
2 users (show)

See Also:


Attachments
Limit the recursion of removeLeftoverAnonymousBoxes to improve performance. (444 bytes, patch)
2006-05-22 14:57 PDT, Dave Hyatt
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Seidel (no email) 2006-01-22 15:10:25 PST
deep appendChild is too slow!  (Safari wins on all but one JavaScript microbenchmark)

http://idanso.dyndns.org/maps/jsbench/

DOM Node.cloneNone and appendChild	Tests speed of shallow Node.cloneNode and deep Node.appendChild	335ms

All the other benchmarks we beat FireFox/MacIE/Opera on the same hardware.  We need to fix this one remaining case.
Comment 1 Keith Anderson 2006-05-22 13:53:19 PDT
According to Shark, appendChild is spending all it's time in  RenderContainer::removeLeftoverAnonymousBoxes(). It's not necessarily due to a deep DOM tree, though. I was able to get numbers for this by appending a relatively small subtree a large number of times.

My test setup uses the DOM API in Cocoa directly. It iteratively creates a small group of elements DIV( P(textNode) INPUT(textNode) ) and appends that to the BODY element in a loop. It then removes everything with [body removeChild:].

It's spending all of it's time in the removeLeftoverAnonymousBoxes() routine, recursively walking up the tree on every call - and it gets called again for each sibling in both directions as each element is added. My understanding of that routine is that it's coalescing any anonymous boxes from neighboring inline elements, as the spec dictates. It just seems to be going about it in a terribly inefficient manner - especially considering none of this ever actually gets rendered to the screen.

I've varied the number of iterations from 100 to 500000 - and performance falls off dramatically as soon as you start getting VM faults. Not really surprising, really, but it effectively makes doing anything remotely complex in terms of DOM/AJAX/Web2.0/Whatever unworkable in Safari. To be fair, Firefox isn't exactly a Ferrari, but it's about an order of magnitude faster than Safari at this task.

To be thorough, I duplicated this test in pure Javascript and executed it from my test application as well (using evaluateWebScript:) with roughly the same results. I expected this as both implementations end up calling into the same WebKit code, but I wanted to be thorough.
Comment 2 Dave Hyatt 2006-05-22 14:37:17 PDT
It's surprising that removeLeftoverAnonymousBoxes would be hit over and over again.  It's only supposed to be hit when a block has to change from having inline children to having block children.  That can only happen once for a block.
Comment 3 Dave Hyatt 2006-05-22 14:39:51 PDT
It's also not clear to me why removeLeftoverAnonymousBoxes recurs up to the parent.  That is totally wrong unless the block that removeLeftoverAnonymousBoxes is invoked on is also anonymous.
Comment 4 Dave Hyatt 2006-05-22 14:57:45 PDT
Created attachment 8465 [details]
Limit the recursion of removeLeftoverAnonymousBoxes to improve performance.

This helps get us closer, but we still don't win.  I think I may be able to totally rewrite this removal check to be much faster.
Comment 5 Dave Hyatt 2006-05-22 15:01:27 PDT
Actually I tried commenting out this method completely and it had no effect on the benchmark whatsoever, so while I appreciate the second comment, maybe you could file a separate bug with your test case.  removeLeftoverAnonymousBoxes does not seem to be relevant to this particular micro-benchmark (but could be relevant to your new test case that you wrote).

Comment 6 Dave Hyatt 2006-05-22 15:01:59 PDT
Comment on attachment 8465 [details]
Limit the recursion of removeLeftoverAnonymousBoxes to improve performance.

This is a nice easy safe change, though, so going ahead and flagging for review.
Comment 7 Dave Hyatt 2006-05-25 22:44:54 PDT
Comment on attachment 8465 [details]
Limit the recursion of removeLeftoverAnonymousBoxes to improve performance.

Not relevant to the reported bug, so removing from here.
Comment 8 Eric Seidel (no email) 2007-09-30 11:37:45 PDT
The link seems to be bad... Strange I even filed this bug.  I have no recollection of what the original test suite was, so I think this should be closed.
Comment 9 Lucas Forschler 2019-02-06 09:03:01 PST
Mass moving XML DOM bugs to the "DOM" Component.