Title: [291508] trunk/Source/WebCore
Revision
291508
Author
[email protected]
Date
2022-03-18 17:19:29 -0700 (Fri, 18 Mar 2022)

Log Message

Optimize AtomHTMLToken::initializeAttributes()
https://bugs.webkit.org/show_bug.cgi?id=238074

Reviewed by Geoffrey Garen.

Use a HashSet to find duplicate attributes instead of doing a linear search.
This is a confirmed 1.2% progression on Speedometer on iMac20,1 via A/B bots.

* html/parser/AtomHTMLToken.h:
(WebCore::AtomHTMLToken::initializeAttributes):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (291507 => 291508)


--- trunk/Source/WebCore/ChangeLog	2022-03-19 00:00:12 UTC (rev 291507)
+++ trunk/Source/WebCore/ChangeLog	2022-03-19 00:19:29 UTC (rev 291508)
@@ -1,3 +1,16 @@
+2022-03-18  Chris Dumez  <[email protected]>
+
+        Optimize AtomHTMLToken::initializeAttributes()
+        https://bugs.webkit.org/show_bug.cgi?id=238074
+
+        Reviewed by Geoffrey Garen.
+
+        Use a HashSet to find duplicate attributes instead of doing a linear search.
+        This is a confirmed 1.2% progression on Speedometer on iMac20,1 via A/B bots.
+
+        * html/parser/AtomHTMLToken.h:
+        (WebCore::AtomHTMLToken::initializeAttributes):
+
 2022-03-18  Jonathan Bedard  <[email protected]>
 
         [iOS 15.4] Fix unused variables

Modified: trunk/Source/WebCore/html/parser/AtomHTMLToken.h (291507 => 291508)


--- trunk/Source/WebCore/html/parser/AtomHTMLToken.h	2022-03-19 00:00:12 UTC (rev 291507)
+++ trunk/Source/WebCore/html/parser/AtomHTMLToken.h	2022-03-19 00:19:29 UTC (rev 291508)
@@ -204,6 +204,8 @@
     if (!size)
         return;
 
+    HashSet<AtomString> addedAttributes;
+    addedAttributes.reserveInitialCapacity(size);
     m_attributes.reserveInitialCapacity(size);
     for (auto& attribute : attributes) {
         if (attribute.name.isEmpty())
@@ -211,8 +213,7 @@
 
         auto qualifiedName = HTMLNameCache::makeAttributeQualifiedName(attribute.name);
 
-        // FIXME: This is N^2 for the number of attributes.
-        if (!hasAttribute(m_attributes, qualifiedName.localName()))
+        if (addedAttributes.add(qualifiedName.localName()).isNewEntry)
             m_attributes.uncheckedAppend(Attribute(WTFMove(qualifiedName), HTMLNameCache::makeAttributeValue(attribute.value)));
         else
             m_hasDuplicateAttribute = HasDuplicateAttribute::Yes;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to