⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 236241 in webkit


Ignore:
Timestamp:
Sep 19, 2018, 11:14:59 PM (8 years ago)
Author:
rniwa@webkit.org
Message:

Improve node statistics for rare data
​https://bugs.webkit.org/show_bug.cgi?id=189775

Reviewed by Simon Fraser.

Report reasons we created NodeRareData and ElementRareData in node statistics.

Added NodeRareData::useTypes and ElementRareData::useTypes which returns OptionSet<NodeRareData::UseType>
indicating which instance member of the rare data is currently in use.

  • dom/Element.cpp:
  • dom/Element.h:
  • dom/ElementRareData.h:

(WebCore::defaultMinimumSizeForResizing):
(WebCore::ElementRareData::useTypes const):

  • dom/Node.cpp:

(WebCore::stringForRareDataUseType):
(WebCore::Node::dumpStatistics):

  • dom/NodeRareData.cpp:
  • dom/NodeRareData.h:

(WebCore::NodeRareData::useTypes const):

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r236228 r236241  
     12018-09-19  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Improve node statistics for rare data
     4        https://bugs.webkit.org/show_bug.cgi?id=189775
     5
     6        Reviewed by Simon Fraser.
     7
     8        Report reasons we created NodeRareData and ElementRareData in node statistics.
     9
     10        Added NodeRareData::useTypes and ElementRareData::useTypes which returns OptionSet<NodeRareData::UseType>
     11        indicating which instance member of the rare data is currently in use.
     12
     13        * dom/Element.cpp:
     14        * dom/Element.h:
     15        * dom/ElementRareData.h:
     16        (WebCore::defaultMinimumSizeForResizing):
     17        (WebCore::ElementRareData::useTypes const):
     18        * dom/Node.cpp:
     19        (WebCore::stringForRareDataUseType):
     20        (WebCore::Node::dumpStatistics):
     21        * dom/NodeRareData.cpp:
     22        * dom/NodeRareData.h:
     23        (WebCore::NodeRareData::useTypes const):
     24
    1252018-09-19  Ryosuke Niwa  <rniwa@webkit.org>
    226
  • trunk/Source/WebCore/dom/Element.cpp

    r235830 r236241  
    34433443#endif
    34443444
    3445 #ifdef DUMP_NODE_STATISTICS
     3445#if DUMP_NODE_STATISTICS
    34463446bool Element::hasNamedNodeMap() const
    34473447{
  • trunk/Source/WebCore/dom/Element.h

    r235806 r236241  
    105105#endif
    106106
    107 #ifdef DUMP_NODE_STATISTICS
     107#if DUMP_NODE_STATISTICS
    108108    bool hasNamedNodeMap() const;
    109109#endif
  • trunk/Source/WebCore/dom/ElementRareData.h

    r234884 r236241  
    3333
    3434namespace WebCore {
     35
     36inline IntSize defaultMinimumSizeForResizing()
     37{
     38    return IntSize(LayoutUnit::max(), LayoutUnit::max());
     39}
    3540
    3641class ElementRareData : public NodeRareData {
    … …  
    121126    IntersectionObserverData* intersectionObserverData() { return m_intersectionObserverData.get(); }
    122127    void setIntersectionObserverData(std::unique_ptr<IntersectionObserverData>&& data) { m_intersectionObserverData = WTFMove(data); }
     128#endif
     129
     130#if DUMP_NODE_STATISTICS
     131    OptionSet<UseType> useTypes() const
     132    {
     133        auto result = NodeRareData::useTypes();
     134        if (m_tabIndexWasSetExplicitly)
     135            result.add(UseType::TabIndex);
     136        if (m_styleAffectedByActive || m_styleAffectedByEmpty || m_styleAffectedByFocusWithin || m_childrenAffectedByHover
     137            || m_childrenAffectedByDrag || m_childrenAffectedByLastChildRules || m_childrenAffectedByForwardPositionalRules
     138            || m_descendantsAffectedByForwardPositionalRules || m_childrenAffectedByBackwardPositionalRules
     139            || m_descendantsAffectedByBackwardPositionalRules || m_childrenAffectedByPropertyBasedBackwardPositionalRules)
     140            result.add(UseType::StyleFlags);
     141        if (m_minimumSizeForResizing != defaultMinimumSizeForResizing())
     142            result.add(UseType::MinimumSize);
     143        if (!m_savedLayerScrollPosition.isZero())
     144            result.add(UseType::ScrollingPosition);
     145        if (m_computedStyle)
     146            result.add(UseType::ComputedStyle);
     147        if (m_dataset)
     148            result.add(UseType::Dataset);
     149        if (m_classList)
     150            result.add(UseType::ClassList);
     151        if (m_shadowRoot)
     152            result.add(UseType::ShadowRoot);
     153        if (m_customElementReactionQueue)
     154            result.add(UseType::CustomElementQueue);
     155        if (m_attributeMap)
     156            result.add(UseType::AttributeMap);
     157        if (m_intersectionObserverData)
     158            result.add(UseType::InteractionObserver);
     159        if (m_beforePseudoElement || m_afterPseudoElement)
     160            result.add(UseType::PseudoElements);
     161        return result;
     162    }
    123163#endif
    124164
    … …  
    166206};
    167207
    168 inline IntSize defaultMinimumSizeForResizing()
    169 {
    170     return IntSize(LayoutUnit::max(), LayoutUnit::max());
    171 }
    172 
    173208inline ElementRareData::ElementRareData(RenderElement* renderer)
    174209    : NodeRareData(renderer)
  • trunk/Source/WebCore/dom/Node.cpp

    r236002 r236241  
    9292    return liveNodes;
    9393}
     94
     95static const char* stringForRareDataUseType(NodeRareData::UseType useType)
     96{
     97    switch (useType) {
     98    case NodeRareData::UseType::ConnectedFrameCount:
     99        return "ConnectedFrameCount";
     100    case NodeRareData::UseType::NodeList:
     101        return "NodeList";
     102    case NodeRareData::UseType::MutationObserver:
     103        return "MutationObserver";
     104    case NodeRareData::UseType::TabIndex:
     105        return "TabIndex";
     106    case NodeRareData::UseType::StyleFlags:
     107        return "StyleFlags";
     108    case NodeRareData::UseType::MinimumSize:
     109        return "MinimumSize";
     110    case NodeRareData::UseType::ScrollingPosition:
     111        return "ScrollingPosition";
     112    case NodeRareData::UseType::ComputedStyle:
     113        return "ComputedStyle";
     114    case NodeRareData::UseType::Dataset:
     115        return "Dataset";
     116    case NodeRareData::UseType::ClassList:
     117        return "ClassList";
     118    case NodeRareData::UseType::ShadowRoot:
     119        return "ShadowRoot";
     120    case NodeRareData::UseType::CustomElementQueue:
     121        return "CustomElementQueue";
     122    case NodeRareData::UseType::AttributeMap:
     123        return "AttributeMap";
     124    case NodeRareData::UseType::InteractionObserver:
     125        return "InteractionObserver";
     126    case NodeRareData::UseType::PseudoElements:
     127        return "PseudoElements";
     128    }
     129    return nullptr;
     130}
     131
    94132#endif
    95133
    … …  
    118156    size_t elementsWithNamedNodeMap = 0;
    119157
     158    HashMap<uint16_t, size_t> rareDataSingleUseTypeCounts;
     159    size_t mixedRareDataUseCount = 0;
     160
    120161    for (auto* node : liveNodeSet()) {
    121162        if (node->hasRareData()) {
    … …  
    126167                    ++elementsWithNamedNodeMap;
    127168            }
     169            auto* rareData = node->rareData();
     170            auto useTypes = is<Element>(node) ? static_cast<ElementRareData*>(rareData)->useTypes() : rareData->useTypes();
     171            unsigned useTypeCount = 0;
     172            for (auto type : useTypes) {
     173                UNUSED_PARAM(type);
     174                useTypeCount++;
     175            }
     176            if (useTypeCount == 1) {
     177                auto result = rareDataSingleUseTypeCounts.add(static_cast<uint16_t>(*useTypes.begin()), 0);
     178                result.iterator->value++;
     179            } else
     180                mixedRareDataUseCount++;
    128181        }
    129182
    … …  
    144197                    for (unsigned i = 0; i < length; ++i) {
    145198                        const Attribute& attr = elementData->attributeAt(i);
    146                         if (!attr.isEmpty())
     199                        if (element.attrIfExists(attr.name()))
    147200                            ++attributesWithAttr;
    148201                    }
    … …  
    189242
    190243    printf("Number of Nodes: %d\n\n", liveNodeSet().size());
    191     printf("Number of Nodes with RareData: %zu\n\n", nodesWithRareData);
     244    printf("Number of Nodes with RareData: %zu\n", nodesWithRareData);
     245    printf("  Mixed use: %zu\n", mixedRareDataUseCount);
     246    for (auto it : rareDataSingleUseTypeCounts)
     247        printf("  %s: %zu\n", stringForRareDataUseType(static_cast<NodeRareData::UseType>(it.key)), it.value);
     248    printf("\n");
     249
    192250
    193251    printf("NodeType distribution:\n");
  • trunk/Source/WebCore/dom/NodeRareData.cpp

    r153772 r236241  
    4141COMPILE_ASSERT(sizeof(NodeRareData) == sizeof(SameSizeAsNodeRareData), NodeRareDataShouldStaySmall);
    4242
     43// Ensure the 10 bits reserved for the m_connectedFrameCount cannot overflow
     44static_assert(Page::maxNumberOfFrames < 1024, "Frame limit should fit in rare data count");
     45
    4346} // namespace WebCore
  • trunk/Source/WebCore/dom/NodeRareData.h

    r219237 r236241  
    2727#include "LiveNodeList.h"
    2828#include "MutationObserverRegistration.h"
    29 #include "Page.h"
    3029#include "QualifiedName.h"
    3130#include "TagCollection.h"
    … …  
    251250    WTF_MAKE_NONCOPYABLE(NodeRareData); WTF_MAKE_FAST_ALLOCATED;
    252251public:
     252#if defined(DUMP_NODE_STATISTICS) && DUMP_NODE_STATISTICS
     253    enum class UseType : uint16_t {
     254        ConnectedFrameCount = 1 << 0,
     255        NodeList = 1 << 1,
     256        MutationObserver = 1 << 2,
     257
     258        TabIndex = 1 << 3,
     259        StyleFlags = 1 << 4,
     260        MinimumSize = 1 << 5,
     261        ScrollingPosition = 1 << 6,
     262        ComputedStyle = 1 << 7,
     263        Dataset = 1 << 8,
     264        ClassList = 1 << 9,
     265        ShadowRoot = 1 << 10,
     266        CustomElementQueue = 1 << 11,
     267        AttributeMap = 1 << 12,
     268        InteractionObserver = 1 << 13,
     269        PseudoElements = 1 << 14,
     270    };
     271#endif
     272
    253273    NodeRareData(RenderObject* renderer)
    254274        : NodeRareDataBase(renderer)
    … …  
    284304        m_connectedFrameCount -= amount;
    285305    }
     306
     307#if DUMP_NODE_STATISTICS
     308    OptionSet<UseType> useTypes() const
     309    {
     310        OptionSet<UseType> result;
     311        if (m_connectedFrameCount)
     312            result.add(UseType::ConnectedFrameCount);
     313        if (m_nodeLists)
     314            result.add(UseType::NodeList);
     315        if (m_mutationObserverData)
     316            result.add(UseType::MutationObserver);
     317        return result;
     318    }
     319#endif
    286320
    287321private:
    … …  
    315349}
    316350
    317 // Ensure the 10 bits reserved for the m_connectedFrameCount cannot overflow
    318 static_assert(Page::maxNumberOfFrames < 1024, "Frame limit should fit in rare data count");
    319 
    320351} // namespace WebCore
Note: See TracChangeset for help on using the changeset viewer.