Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: cd3c9890ec057999b7580d14cc738c3b51ab0407
      
https://github.com/WebKit/WebKit/commit/cd3c9890ec057999b7580d14cc738c3b51ab0407
  Author: Nathan Solomon <[email protected]>
  Date:   2025-11-15 (Sat, 15 Nov 2025)

  Changed paths:
    A LayoutTests/fast/parser/innerHTML-cache-mutation-test-expected.txt
    A LayoutTests/fast/parser/innerHTML-cache-mutation-test.html
    A LayoutTests/fast/parser/innerHTML-prefix-cache-boundary-test-expected.txt
    A LayoutTests/fast/parser/innerHTML-prefix-cache-boundary-test.html
    M Source/WebCore/css/CSSStyleProperties.cpp
    M Source/WebCore/dom/ContainerNode.cpp
    M Source/WebCore/dom/ContainerNode.h
    M Source/WebCore/dom/Document.cpp
    M Source/WebCore/dom/Document.h
    M Source/WebCore/dom/DocumentFragment.cpp
    M Source/WebCore/dom/Element.cpp
    M Source/WebCore/dom/Element.h
    M Source/WebCore/dom/Node.cpp
    M Source/WebCore/dom/Node.h
    M Source/WebCore/dom/ShadowRoot.cpp
    M Source/WebCore/dom/StyledElement.cpp
    M Source/WebCore/html/parser/HTMLDocumentParserFastPath.cpp
    M Source/WebCore/html/parser/HTMLDocumentParserFastPath.h

  Log Message:
  -----------
  Cache prefixes of previously seen input when setting innerHTML
https://bugs.webkit.org/show_bug.cgi?id=301231
rdar://162555307

Reviewed by Ryosuke Niwa.

When a user sets innerHTML to an element, the next call to
innerHTML can often be just an extension of the previous markup.
Regardless, we reparse the entire input.
We can add a prefix match detection to tell the parser if the current
input to innerHTML is just an extension of a previous input.
If so, avoid jumping into the parser, deep clone the existing
tree, then just parse the unseen markup.
A prefix can also just be considered an exact match of a previous input.

This is 10% win on TODOMVC.Jquery.AddingAllItems.

Combined changes:
Tests: fast/parser/innerHTML-cache-mutation-test.html
       fast/parser/innerHTML-prefix-cache-boundary-test.html
* LayoutTests/fast/parser/innerHTML-cache-mutation-test-expected.txt: Added.
* LayoutTests/fast/parser/innerHTML-cache-mutation-test.html: Added.
* LayoutTests/fast/parser/innerHTML-prefix-cache-boundary-test-expected.txt: 
Added.
* LayoutTests/fast/parser/innerHTML-prefix-cache-boundary-test.html: Added.
* Source/WebCore/css/CSSStyleProperties.cpp:
(WebCore::InlineCSSStyleProperties::didMutate):
* Source/WebCore/dom/ContainerNode.cpp:
(WebCore::ContainerNode::parserNotifyChildrenChanged):
(WebCore::ContainerNode::childrenChanged):
(WebCore::ContainerNode::cloneSubtreeForFastParser const):
* Source/WebCore/dom/ContainerNode.h:
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::invalidateCachedSetInnerHTML):
(WebCore::Document::updateCachedSetInnerHTML):
* Source/WebCore/dom/Document.h:
(WebCore::Document::cachedSetInnerHTML):
* Source/WebCore/dom/DocumentFragment.cpp:
(WebCore::DocumentFragment::parseHTML):
* Source/WebCore/dom/Element.cpp:
(WebCore::Element::notifyAttributeChanged):
(WebCore::Element::classAttributeChanged):
(WebCore::Element::parserSetAttributes):
(WebCore::Element::replaceChildrenWithMarkup):
* Source/WebCore/dom/Element.h:
* Source/WebCore/dom/Node.cpp:
(WebCore::Node::invalidateNodeListCollectionAndInnerHTMLPrefixCachesInAncestorsForAttribute):
(WebCore::Node::setDidMutateSubtreeAfterSetInnerHTMLOnAncestors):
(WebCore::Node::setTextContent):
(WebCore::Node::invalidateNodeListAndCollectionCachesInAncestorsForAttribute): 
Deleted.
* Source/WebCore/dom/Node.h:
(WebCore::Node::hasDidMutateSubtreeAfterSetInnerHTML const):
(WebCore::Node::setDidMutateSubtreeAfterSetInnerHTML):
(WebCore::Node::clearDidMutateSubtreeAfterSetInnerHTML):
(WebCore::Node::hasWasParsedWithFastPath const):
(WebCore::Node::setWasParsedWithFastPath):
(WebCore::Node::clearWasParsedWithFastPath):
* Source/WebCore/dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::replaceChildrenWithMarkup):
* Source/WebCore/dom/StyledElement.cpp:
(WebCore::StyledElement::inlineStyleChanged):
* Source/WebCore/html/parser/HTMLDocumentParserFastPath.cpp:
(WebCore::maxCachedSetInnerHTMLStringSize):
(WebCore::isCachedSubtreeValid):
(WebCore::isCachedPrefixMatch):
(WebCore::tryAvoidParsingByCloningExistingSubtree):
(WebCore::cloneCachedPrefixAndParseSuffix):
(WebCore::HTMLFastPathParser::parseAttributes):
(WebCore::tryFastParsingHTMLFragmentImpl):
* Source/WebCore/html/parser/HTMLDocumentParserFastPath.h:

Canonical link: https://commits.webkit.org/303089@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to