Changeset 289991 in webkit


Ignore:
Timestamp:
Feb 16, 2022 7:21:00 PM (2 years ago)
Author:
Cameron McCormack
Message:

Cache an entire attribute QualifiedName when parsing HTML, not just its local name AtomString
https://bugs.webkit.org/show_bug.cgi?id=236570
<rdar://problem/88876545>

Reviewed by Darin Adler.

Bug 229907 added HTMLAtomStringCache, which uses a fast to compute hash
that works well to cache HTML tag names, attribute names, and attribute
values. When AtomHTMLToken initializes its list of Attributes, it uses
HTMLAtomStringCache to look up or create an AtomString for the
attribute's local name, and then creates a QualifiedName to wrap it.
QualifiedName construction involves looking up QualifiedNameCache, which
is a thread-specific cache of QualifiedNameImpl objects. If we make
HTMLAtomStringCache responsible for caching an attribute's QualifiedName
instead of just its local name AtomString, we can avoid the work of
looking up the QualifiedNameCache.

To reflect its broader responsibilities, HTMLAtomStringCache is renamed
to HTMLNameCache.

Doing this results in a 0.2-0.3% improvement on Speedometer 2, and a
0.3-0.4% improvement on PLT5 (with the lower end of those ranges being
on Apple Silicon and the higher end on Intel).

  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • dom/QualifiedName.h:

(WebCore::QualifiedName::QualifiedName):

  • html/parser/AtomHTMLToken.h:

(WebCore::AtomHTMLToken::initializeAttributes):
(WebCore::AtomHTMLToken::AtomHTMLToken):

  • html/parser/HTMLAtomStringCache.h: Removed.

(WebCore::HTMLAtomStringCache::makeTagOrAttributeName): Deleted.
(WebCore::HTMLAtomStringCache::makeAttributeValue): Deleted.
(WebCore::HTMLAtomStringCache::clear): Deleted.
(WebCore::HTMLAtomStringCache::make): Deleted.
(WebCore::HTMLAtomStringCache::cacheSlot): Deleted.

  • html/parser/HTMLNameCache.cpp: Renamed from Source/WebCore/html/parser/HTMLAtomStringCache.cpp.

(WebCore::HTMLNameCache::atomStringCache):
(WebCore::HTMLNameCache::qualifiedNameCache):

  • html/parser/HTMLNameCache.h: Added.

(WebCore::HTMLNameCache::makeTagName):
(WebCore::HTMLNameCache::makeAttributeQualifiedName):
(WebCore::HTMLNameCache::makeAttributeValue):
(WebCore::HTMLNameCache::clear):
(WebCore::HTMLNameCache::makeAtomString):
(WebCore::HTMLNameCache::makeQualifiedName):
(WebCore::HTMLNameCache::slotIndex):
(WebCore::HTMLNameCache::atomStringCacheSlot):
(WebCore::HTMLNameCache::qualifiedNameCacheSlot):

  • page/MemoryRelease.cpp:

(WebCore::releaseNoncriticalMemory):

  • page/cocoa/MemoryReleaseCocoa.mm:

(WebCore::jettisonExpensiveObjectsOnTopLevelNavigation):

Location:
trunk/Source/WebCore
Files:
1 added
1 deleted
7 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r289989 r289991  
     12022-02-16  Cameron McCormack  <heycam@apple.com>
     2
     3        Cache an entire attribute QualifiedName when parsing HTML, not just its local name AtomString
     4        https://bugs.webkit.org/show_bug.cgi?id=236570
     5        <rdar://problem/88876545>
     6
     7        Reviewed by Darin Adler.
     8
     9        Bug 229907 added HTMLAtomStringCache, which uses a fast to compute hash
     10        that works well to cache HTML tag names, attribute names, and attribute
     11        values. When AtomHTMLToken initializes its list of Attributes, it uses
     12        HTMLAtomStringCache to look up or create an AtomString for the
     13        attribute's local name, and then creates a QualifiedName to wrap it.
     14        QualifiedName construction involves looking up QualifiedNameCache, which
     15        is a thread-specific cache of QualifiedNameImpl objects. If we make
     16        HTMLAtomStringCache responsible for caching an attribute's QualifiedName
     17        instead of just its local name AtomString, we can avoid the work of
     18        looking up the QualifiedNameCache.
     19
     20        To reflect its broader responsibilities, HTMLAtomStringCache is renamed
     21        to HTMLNameCache.
     22
     23        Doing this results in a 0.2-0.3% improvement on Speedometer 2, and a
     24        0.3-0.4% improvement on PLT5 (with the lower end of those ranges being
     25        on Apple Silicon and the higher end on Intel).
     26
     27        * Sources.txt:
     28        * WebCore.xcodeproj/project.pbxproj:
     29        * dom/QualifiedName.h:
     30        (WebCore::QualifiedName::QualifiedName):
     31        * html/parser/AtomHTMLToken.h:
     32        (WebCore::AtomHTMLToken::initializeAttributes):
     33        (WebCore::AtomHTMLToken::AtomHTMLToken):
     34        * html/parser/HTMLAtomStringCache.h: Removed.
     35        (WebCore::HTMLAtomStringCache::makeTagOrAttributeName): Deleted.
     36        (WebCore::HTMLAtomStringCache::makeAttributeValue): Deleted.
     37        (WebCore::HTMLAtomStringCache::clear): Deleted.
     38        (WebCore::HTMLAtomStringCache::make): Deleted.
     39        (WebCore::HTMLAtomStringCache::cacheSlot): Deleted.
     40        * html/parser/HTMLNameCache.cpp: Renamed from Source/WebCore/html/parser/HTMLAtomStringCache.cpp.
     41        (WebCore::HTMLNameCache::atomStringCache):
     42        (WebCore::HTMLNameCache::qualifiedNameCache):
     43        * html/parser/HTMLNameCache.h: Added.
     44        (WebCore::HTMLNameCache::makeTagName):
     45        (WebCore::HTMLNameCache::makeAttributeQualifiedName):
     46        (WebCore::HTMLNameCache::makeAttributeValue):
     47        (WebCore::HTMLNameCache::clear):
     48        (WebCore::HTMLNameCache::makeAtomString):
     49        (WebCore::HTMLNameCache::makeQualifiedName):
     50        (WebCore::HTMLNameCache::slotIndex):
     51        (WebCore::HTMLNameCache::atomStringCacheSlot):
     52        (WebCore::HTMLNameCache::qualifiedNameCacheSlot):
     53        * page/MemoryRelease.cpp:
     54        (WebCore::releaseNoncriticalMemory):
     55        * page/cocoa/MemoryReleaseCocoa.mm:
     56        (WebCore::jettisonExpensiveObjectsOnTopLevelNavigation):
     57
    1582022-02-16  Megan Gardner  <megan_gardner@apple.com>
    259
  • trunk/Source/WebCore/Sources.txt

    r289978 r289991  
    14111411html/forms/FileIconLoader.cpp
    14121412html/parser/CSSPreloadScanner.cpp
    1413 html/parser/HTMLAtomStringCache.cpp
    14141413html/parser/HTMLConstructionSite.cpp
    14151414html/parser/HTMLDocumentParser.cpp
     
    14191418html/parser/HTMLFormattingElementList.cpp
    14201419html/parser/HTMLMetaCharsetParser.cpp
     1420html/parser/HTMLNameCache.cpp
    14211421html/parser/HTMLParserIdioms.cpp
    14221422html/parser/HTMLParserOptions.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r289978 r289991  
    55515551                F49786881FF45FA500E060AB /* PasteboardItemInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = F49786871FF45FA500E060AB /* PasteboardItemInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
    55525552                F4A064C8277E48C900B06A17 /* FontCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = F4A064C6277E48C600B06A17 /* FontCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
    5553                 F4B0018926E7F21F006EAABE /* HTMLAtomStringCache.h in Headers */ = {isa = PBXBuildFile; fileRef = F4B0018726E7F21F006EAABE /* HTMLAtomStringCache.h */; };
     5553                F4B0018926E7F21F006EAABE /* HTMLNameCache.h in Headers */ = {isa = PBXBuildFile; fileRef = F4B0018726E7F21F006EAABE /* HTMLNameCache.h */; };
    55545554                F4B2A909265030BA009E7286 /* DataDetectorHighlight.h in Headers */ = {isa = PBXBuildFile; fileRef = F4B2A90626502BA0009E7286 /* DataDetectorHighlight.h */; };
    55555555                F4B422C4220C0568009E1E7D /* DOMPasteAccess.h in Headers */ = {isa = PBXBuildFile; fileRef = F4B422C2220C0000009E1E7D /* DOMPasteAccess.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    1786517865                F49E98E421DEE6C1009AE55E /* EditAction.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = EditAction.cpp; sourceTree = "<group>"; };
    1786617866                F4A064C6277E48C600B06A17 /* FontCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontCocoa.h; sourceTree = "<group>"; };
    17867                 F4B0018726E7F21F006EAABE /* HTMLAtomStringCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HTMLAtomStringCache.h; sourceTree = "<group>"; };
    17868                 F4B0018826E7F21F006EAABE /* HTMLAtomStringCache.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLAtomStringCache.cpp; sourceTree = "<group>"; };
     17867                F4B0018726E7F21F006EAABE /* HTMLNameCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HTMLNameCache.h; sourceTree = "<group>"; };
     17868                F4B0018826E7F21F006EAABE /* HTMLNameCache.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLNameCache.cpp; sourceTree = "<group>"; };
    1786917869                F4B2A90626502BA0009E7286 /* DataDetectorHighlight.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DataDetectorHighlight.h; sourceTree = "<group>"; };
    1787017870                F4B2A90826502BC0009E7286 /* DataDetectorHighlight.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DataDetectorHighlight.mm; sourceTree = "<group>"; };
     
    2640326403                                977B3849122883E900B81FF8 /* CSSPreloadScanner.cpp */,
    2640426404                                977B384A122883E900B81FF8 /* CSSPreloadScanner.h */,
    26405                                 F4B0018826E7F21F006EAABE /* HTMLAtomStringCache.cpp */,
    26406                                 F4B0018726E7F21F006EAABE /* HTMLAtomStringCache.h */,
    2640726405                                977B384B122883E900B81FF8 /* HTMLConstructionSite.cpp */,
    2640826406                                977B384C122883E900B81FF8 /* HTMLConstructionSite.h */,
     
    2642226420                                2BE8E2C812A58A0100FAD550 /* HTMLMetaCharsetParser.cpp */,
    2642326421                                2BE8E2C612A589EC00FAD550 /* HTMLMetaCharsetParser.h */,
     26422                                F4B0018826E7F21F006EAABE /* HTMLNameCache.cpp */,
     26423                                F4B0018726E7F21F006EAABE /* HTMLNameCache.h */,
    2642426424                                93E2A304123E9DC0009FE12A /* HTMLParserIdioms.cpp */,
    2642526425                                93E2A305123E9DC0009FE12A /* HTMLParserIdioms.h */,
     
    3477934779                                CD1F9B7D270E667800617EB6 /* HTMLAnchorElementInlines.h in Headers */,
    3478034780                                A8EA7D2E0A19385500A8EF5F /* HTMLAreaElement.h in Headers */,
    34781                                 F4B0018926E7F21F006EAABE /* HTMLAtomStringCache.h in Headers */,
    3478234781                                7C5F28FC1A827D8400C0F31F /* HTMLAttachmentElement.h in Headers */,
    3478334782                                E44613A20CD6331000FADA75 /* HTMLAudioElement.h in Headers */,
     
    3484634845                                7177AD57274295D1002F103B /* HTMLModelElementCamera.h in Headers */,
    3484734846                                A8CFF7A70A156978000A4234 /* HTMLModElement.h in Headers */,
     34847                                F4B0018926E7F21F006EAABE /* HTMLNameCache.h in Headers */,
    3484834848                                A8DF3FD4097FA0FC0052981B /* HTMLNameCollection.h in Headers */,
    3484934849                                A871D45A0A127CBC00B12A68 /* HTMLObjectElement.h in Headers */,
  • trunk/Source/WebCore/dom/QualifiedName.h

    r275410 r289991  
    7373
    7474    WEBCORE_EXPORT QualifiedName(const AtomString& prefix, const AtomString& localName, const AtomString& namespaceURI);
     75    QualifiedName(QualifiedNameImpl& impl) : m_impl(&impl) { }
    7576    explicit QualifiedName(WTF::HashTableDeletedValueType) : m_impl(WTF::HashTableDeletedValue) { }
    7677    bool isHashTableDeletedValue() const { return m_impl.isHashTableDeletedValue(); }
  • trunk/Source/WebCore/html/parser/AtomHTMLToken.h

    r286860 r289991  
    2727#pragma once
    2828
    29 #include "HTMLAtomStringCache.h"
     29#include "HTMLNameCache.h"
    3030#include "HTMLToken.h"
    3131
     
    210210            continue;
    211211
    212         auto localName = HTMLAtomStringCache::makeTagOrAttributeName(attribute.name);
     212        auto qualifiedName = HTMLNameCache::makeAttributeQualifiedName(attribute.name);
    213213
    214214        // FIXME: This is N^2 for the number of attributes.
    215         if (!hasAttribute(m_attributes, localName))
    216             m_attributes.uncheckedAppend(Attribute(QualifiedName(nullAtom(), localName, nullAtom()), HTMLAtomStringCache::makeAttributeValue(attribute.value)));
     215        if (!hasAttribute(m_attributes, qualifiedName.localName()))
     216            m_attributes.uncheckedAppend(Attribute(WTFMove(qualifiedName), HTMLNameCache::makeAttributeValue(attribute.value)));
    217217        else
    218218            m_hasDuplicateAttribute = HasDuplicateAttribute::Yes;
     
    228228        return;
    229229    case HTMLToken::DOCTYPE:
    230         m_name = HTMLAtomStringCache::makeTagOrAttributeName(token.name());
     230        m_name = HTMLNameCache::makeTagName(token.name());
    231231        m_doctypeData = token.releaseDoctypeData();
    232232        return;
     
    236236    case HTMLToken::EndTag:
    237237        m_selfClosing = token.selfClosing();
    238         m_name = HTMLAtomStringCache::makeTagOrAttributeName(token.name());
     238        m_name = HTMLNameCache::makeTagName(token.name());
    239239        initializeAttributes(token.attributes());
    240240        return;
  • trunk/Source/WebCore/html/parser/HTMLNameCache.cpp

    r289990 r289991  
    2525
    2626#include "config.h"
    27 #include "HTMLAtomStringCache.h"
     27#include "HTMLNameCache.h"
    2828
    2929namespace WebCore {
    3030
    31 HTMLAtomStringCache::Cache& HTMLAtomStringCache::cache(Type type)
     31HTMLNameCache::AtomStringCache& HTMLNameCache::atomStringCache(AtomStringType type)
    3232{
    33     static MainThreadNeverDestroyed<Cache> caches[2];
     33    static MainThreadNeverDestroyed<AtomStringCache> caches[2];
    3434    return caches[static_cast<size_t>(type)].get();
    3535}
    3636
     37HTMLNameCache::QualifiedNameCache& HTMLNameCache::qualifiedNameCache()
     38{
     39    static MainThreadNeverDestroyed<QualifiedNameCache> cache;
     40    return cache.get();
     41}
     42
    3743} // namespace WebCore
  • trunk/Source/WebCore/page/MemoryRelease.cpp

    r286625 r289991  
    3939#include "Frame.h"
    4040#include "GCController.h"
    41 #include "HTMLAtomStringCache.h"
    4241#include "HTMLMediaElement.h"
     42#include "HTMLNameCache.h"
    4343#include "InlineStyleSheetOwner.h"
    4444#include "InspectorInstrumentation.h"
     
    9090
    9191    InlineStyleSheetOwner::clearCache();
    92     HTMLAtomStringCache::clear();
     92    HTMLNameCache::clear();
    9393}
    9494
  • trunk/Source/WebCore/page/cocoa/MemoryReleaseCocoa.mm

    r282142 r289991  
    2929#import "FontFamilySpecificationCoreText.h"
    3030#import "GCController.h"
    31 #import "HTMLAtomStringCache.h"
     31#import "HTMLNameCache.h"
    3232#import "IOSurfacePool.h"
    3333#import "LayerPool.h"
     
    102102#endif
    103103
    104     HTMLAtomStringCache::clear();
     104    HTMLNameCache::clear();
    105105}
    106106
Note: See TracChangeset for help on using the changeset viewer.