12011-02-09 Andy Estes <aestes@apple.com>
2
3 Reviewed by NOBODY (OOPS!).
4
5 HTML5 TreeBuilder regressed a Peacekeeper DOM test by 40%
6 https://bugs.webkit.org/show_bug.cgi?id=48719
7
8 The HTML5 fragment parsing algorithm specifies that a new Document
9 should be created to serve as the temporary parent of fragment nodes
10 during parsing. Document creation is expensive and accounts for ~38% of
11 the Peacekeeper DOM performance regression. Avoid the cost of creating
12 a dummy document by using the already-created DocumentFragment as the
13 root node during fragment parsing.
14
15 With this patch, the regression in Peacekeeper from Safari 5.0.3 to ToT
16 is ~24%.
17
18 Test: fast/parser/fragment-parser-doctype.html
19
20 * dom/ContainerNode.h:
21 (WebCore::ContainerNode::firstElementChild): Add a method that returns
22 the first element-typed child from a ContainerNode.
23 * dom/Document.cpp:
24 (WebCore::Document::cacheDocumentElement): Call
25 ContainerNode::firstElementChild() to retrieve and cache the document
26 element.
27 * html/parser/HTMLConstructionSite.cpp:
28 (WebCore::HTMLConstructionSite::HTMLConstructionSite): Initialize the
29 root ContainerNode.
30 (WebCore::HTMLConstructionSite::detach): Clear the reference to the
31 root ContainerNode.
32 (WebCore::HTMLConstructionSite::insertHTMLHtmlStartTagBeforeHTML):
33 Attach the new element to the root ContainerNode.
34 (WebCore::HTMLConstructionSite::insertDoctype): Ditto.
35 (WebCore::HTMLConstructionSite::insertCommentOnDocument): Ditto.
36 * html/parser/HTMLConstructionSite.h: Store a pointer to a
37 ContainerNode that will be used as the root node for document parsing.
38 This node might or might not be the same as m_document.
39 * html/parser/HTMLTreeBuilder.cpp:
40 (WebCore::HTMLTreeBuilder::HTMLTreeBuilder): Initialize the
41 HTMLConstructionSite with the correct root ContainerNode based on
42 whether or not we're parsing a fragment.
43 (WebCore::HTMLTreeBuilder::FragmentParsingContext::FragmentParsingContext):
44 Remove m_dummyDocumentForFragmentParsing.
45 (WebCore::HTMLTreeBuilder::FragmentParsingContext::finished): If the
46 fragment has a context element, store only the children of the root
47 element (HTML5 Section 10.4, Step 7).
48 * html/parser/HTMLTreeBuilder.h:
49