[webkit-changes] [WebKit/WebKit] 236ad6: Introduce fast path for innerHTML
Chris Dumez
noreply at github.com
Fri Feb 10 23:53:29 PST 2023
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 236ad6cad0564c857858202c291d383ec4a31a60
https://github.com/WebKit/WebKit/commit/236ad6cad0564c857858202c291d383ec4a31a60
Author: Chris Dumez <cdumez at apple.com>
Date: 2023-02-10 (Fri, 10 Feb 2023)
Changed paths:
M Source/WTF/wtf/text/WTFString.h
M Source/WebCore/Sources.txt
M Source/WebCore/WebCore.xcodeproj/project.pbxproj
M Source/WebCore/dom/Document.h
M Source/WebCore/editing/markup.cpp
M Source/WebCore/html/HTMLBDIElement.cpp
M Source/WebCore/html/HTMLButtonElement.cpp
M Source/WebCore/html/HTMLButtonElement.h
M Source/WebCore/html/HTMLElement.cpp
M Source/WebCore/html/HTMLInputElement.cpp
M Source/WebCore/html/HTMLLabelElement.cpp
M Source/WebCore/html/HTMLLabelElement.h
M Source/WebCore/html/HTMLSelectElement.cpp
M Source/WebCore/html/HTMLSelectElement.h
A Source/WebCore/html/parser/HTMLDocumentParserFastPath.cpp
A Source/WebCore/html/parser/HTMLDocumentParserFastPath.h
M Source/WebCore/html/parser/HTMLEntityParser.cpp
M Source/WebCore/html/parser/HTMLEntityParser.h
M Source/WebCore/html/parser/HTMLNameCache.h
Log Message:
-----------
Introduce fast path for innerHTML
https://bugs.webkit.org/show_bug.cgi?id=252054
Reviewed by Darin Adler.
This patch imports the new fast HTML parser from Blink:
https://bugs.chromium.org/p/chromium/issues/detail?id=1407201
This patch adds a new parser that handles a subset of HTML and is only used by
Element::set[Inner|Outer]HTML. While limited, the hope is this parser is
useful for a number of pages. We could expand on the set of cases this handles
in the future.
As a sanity check, there is a debug assertion in place to make sure that the
fast path generates the same output as the full HTML parser would have.
This is a verified 2.25% progression on Speedometer on macOS and 2.60%
progression on iOS.
* Source/WTF/wtf/text/WTFString.h:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/dom/Document.h:
(WebCore::Document::isDirAttributeDirty const):
(WebCore::Document::setIsDirAttributeDirty):
(WebCore::Document::isTemplateDocument const):
* Source/WebCore/editing/markup.cpp:
(WebCore::createFragmentForMarkup):
* Source/WebCore/html/HTMLBDIElement.cpp:
(WebCore::HTMLBDIElement::HTMLBDIElement):
* Source/WebCore/html/HTMLButtonElement.cpp:
(WebCore::HTMLButtonElement::create):
* Source/WebCore/html/HTMLButtonElement.h:
* Source/WebCore/html/HTMLElement.cpp:
(WebCore::HTMLElement::childrenChanged):
(WebCore::HTMLElement::dirAttributeChanged):
* Source/WebCore/html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::~HTMLInputElement):
(WebCore::HTMLInputElement::needsSuspensionCallback):
We have an optimization in HTMLInputElement which delays the initialization of
m_inputType when constructed by the HTML parser. However, in the fast-parsing
case, we may now fail parsing (due to limited support) in the middle of parsing
an HTMLInputElement. As a result, we may end up destroying an HTMLInputElement
before its m_inputType gets initialized, which would cause a crash. I added a
couple of null checks for m_inputType so that the HTMLInputElement destructor
can run even if m_inputType wasn't initialized yet.
* Source/WebCore/html/HTMLLabelElement.cpp:
(WebCore::HTMLLabelElement::create):
* Source/WebCore/html/HTMLLabelElement.h:
* Source/WebCore/html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::create):
* Source/WebCore/html/HTMLSelectElement.h:
* Source/WebCore/html/parser/HTMLDocumentParserFastPath.cpp: Added.
(WebCore::operator==):
(WebCore::onlyContainsLowercaseASCIILetters):
(WebCore::tagNameHash):
(WebCore::HTMLFastPathParser::HTMLFastPathParser):
(WebCore::HTMLFastPathParser::parse):
(WebCore::HTMLFastPathParser::parseResult const):
(WebCore::HTMLFastPathParser::TagInfo::Tag::create):
(WebCore::HTMLFastPathParser::TagInfo::Tag::allowedInPhrasingOrFlowContent):
(WebCore::HTMLFastPathParser::TagInfo::Tag::allowedInFlowContent):
(WebCore::HTMLFastPathParser::TagInfo::ContainerTag::parseChild):
(WebCore::HTMLFastPathParser::TagInfo::ContainsPhrasingContentTag::parseChild):
(WebCore::HTMLFastPathParser::TagInfo::A::parseChild):
(WebCore::HTMLFastPathParser::TagInfo::AWithPhrasingContent::parseChild):
(WebCore::HTMLFastPathParser::TagInfo::B::create):
(WebCore::HTMLFastPathParser::TagInfo::Footer::create):
(WebCore::HTMLFastPathParser::TagInfo::I::create):
(WebCore::HTMLFastPathParser::TagInfo::Input::create):
(WebCore::HTMLFastPathParser::TagInfo::Option::parseChild):
(WebCore::HTMLFastPathParser::TagInfo::Ol::parseChild):
(WebCore::HTMLFastPathParser::TagInfo::Select::parseChild):
(WebCore::HTMLFastPathParser::TagInfo::Strong::create):
(WebCore::HTMLFastPathParser::TagInfo::Ul::parseChild):
(WebCore::HTMLFastPathParser::parseCompleteInput):
(WebCore::HTMLFastPathParser::isWhitespace):
(WebCore::HTMLFastPathParser::isValidUnquotedAttributeValueChar):
(WebCore::HTMLFastPathParser::isValidAttributeNameChar):
(WebCore::HTMLFastPathParser::isCharAfterTagNameOrAttribute):
(WebCore::HTMLFastPathParser::isCharAfterUnquotedAttribute):
(WebCore::HTMLFastPathParser::skipWhitespace):
(WebCore::HTMLFastPathParser::scanText):
(WebCore::HTMLFastPathParser::scanEscapedText):
(WebCore::HTMLFastPathParser::scanTagName):
(WebCore::HTMLFastPathParser::scanAttributeName):
(WebCore::HTMLFastPathParser::scanAttributeValue):
(WebCore::HTMLFastPathParser::scanEscapedAttributeValue):
(WebCore::HTMLFastPathParser::scanHTMLCharacterReference):
(WebCore::HTMLFastPathParser::didFail):
(WebCore::HTMLFastPathParser::peekNext):
(WebCore::HTMLFastPathParser::consumeNext):
(WebCore::HTMLFastPathParser::parseChildren):
(WebCore::HTMLFastPathParser::processAttribute):
(WebCore::HTMLFastPathParser::parseAttributes):
(WebCore::HTMLFastPathParser::parseSpecificElements):
(WebCore::HTMLFastPathParser::parseElement):
(WebCore::HTMLFastPathParser::parseElementAfterTagName):
(WebCore::HTMLFastPathParser::parseContainerElement):
(WebCore::HTMLFastPathParser::parseVoidElement):
(WebCore::canUseFastPath):
(WebCore::tryFastParsingHTMLFragmentImpl):
(WebCore::tryFastParsingHTMLFragment):
* Source/WebCore/html/parser/HTMLDocumentParserFastPath.h: Added.
* Source/WebCore/html/parser/HTMLEntityParser.cpp:
(WebCore::appendLegalEntityFor):
* Source/WebCore/html/parser/HTMLEntityParser.h:
* Source/WebCore/html/parser/HTMLNameCache.h:
(WebCore::HTMLNameCache::makeAttributeQualifiedName):
(WebCore::HTMLNameCache::makeQualifiedName):
Canonical link: https://commits.webkit.org/260148@main
More information about the webkit-changes
mailing list