[webkit-changes] [WebKit/WebKit] 6a6005: We should cache the first base element in Document

Yusuke Suzuki noreply at github.com
Thu Nov 2 17:57:59 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 6a6005d1bc7feef0f500d36e1d05677d06c050bd
      https://github.com/WebKit/WebKit/commit/6a6005d1bc7feef0f500d36e1d05677d06c050bd
  Author: Yusuke Suzuki <ysuzuki at apple.com>
  Date:   2023-11-02 (Thu, 02 Nov 2023)

  Changed paths:
    M Source/WebCore/dom/Document.cpp
    M Source/WebCore/dom/Document.h
    M Source/WebCore/dom/SelectorQuery.cpp

  Log Message:
  -----------
  We should cache the first base element in Document
https://bugs.webkit.org/show_bug.cgi?id=264113
rdar://117871556

Reviewed by Ryosuke Niwa.

Sometimes, we consume much time for document.querySelector("base"),
because this document ends up not having `base`. It means that it is traversing all the tree.
But this traversal is already paid cost when we call Document::processBaseElement, which is called
everytime `base` element is inserted or removed into the document to update baseURL. So we should just
cache the first element here, and use this information in querySelector and querySelectorAll.

This patch adds Document::firstBaseElement and adding a fast path for querySelector and querySelectorAll.
querySelector uses this element directly. And querySelectorAll stops traversal when this firstBaseElement is nullptr.

* Source/WebCore/dom/Document.cpp:
(WebCore::Document::firstBaseElement const):
(WebCore::Document::processBaseElement):
* Source/WebCore/dom/Document.h:
* Source/WebCore/dom/SelectorQuery.cpp:
(WebCore::elementsForLocalName):

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




More information about the webkit-changes mailing list