Changeset 190842 in webkit


Ignore:
Timestamp:
Oct 10, 2015 2:13:15 PM (9 years ago)
Author:
akling@apple.com
Message:

Reduce pointless malloc traffic in ElementRuleCollector.
<https://webkit.org/b/150003>

Reviewed by Antti Koivisto.

Don't use a unique_ptr for the m_matchedRules vector in ElementRuleCollector.
This is one of our heaviest sources of transient allocations, with ~88000
malloc/free pairs on loading theverge.com.

  • css/ElementRuleCollector.cpp:

(WebCore::ElementRuleCollector::addMatchedRule):
(WebCore::ElementRuleCollector::clearMatchedRules):
(WebCore::ElementRuleCollector::sortAndTransferMatchedRules):
(WebCore::ElementRuleCollector::sortMatchedRules):
(WebCore::ElementRuleCollector::hasAnyMatchingRules):

  • css/ElementRuleCollector.h:

(WebCore::ElementRuleCollector::hasMatchedRules):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r190841 r190842  
     12015-10-10  Andreas Kling  <akling@apple.com>
     2
     3        Reduce pointless malloc traffic in ElementRuleCollector.
     4        <https://webkit.org/b/150003>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Don't use a unique_ptr for the m_matchedRules vector in ElementRuleCollector.
     9        This is one of our heaviest sources of transient allocations, with ~88000
     10        malloc/free pairs on loading theverge.com.
     11
     12        * css/ElementRuleCollector.cpp:
     13        (WebCore::ElementRuleCollector::addMatchedRule):
     14        (WebCore::ElementRuleCollector::clearMatchedRules):
     15        (WebCore::ElementRuleCollector::sortAndTransferMatchedRules):
     16        (WebCore::ElementRuleCollector::sortMatchedRules):
     17        (WebCore::ElementRuleCollector::hasAnyMatchingRules):
     18        * css/ElementRuleCollector.h:
     19        (WebCore::ElementRuleCollector::hasMatchedRules):
     20
    1212015-10-10  Dan Bernstein  <mitz@apple.com>
    222
  • trunk/Source/WebCore/css/ElementRuleCollector.cpp

    r190680 r190842  
    9090inline void ElementRuleCollector::addMatchedRule(const MatchedRule& matchedRule)
    9191{
    92     if (!m_matchedRules)
    93         m_matchedRules = std::make_unique<Vector<MatchedRule, 32>>();
    94     m_matchedRules->append(matchedRule);
     92    m_matchedRules.append(matchedRule);
    9593}
    9694
    9795void ElementRuleCollector::clearMatchedRules()
    9896{
    99     if (!m_matchedRules)
    100         return;
    101     m_matchedRules->clear();
     97    m_matchedRules.clear();
    10298}
    10399
     
    167163void ElementRuleCollector::sortAndTransferMatchedRules()
    168164{
    169     if (!m_matchedRules || m_matchedRules->isEmpty())
     165    if (m_matchedRules.isEmpty())
    170166        return;
    171167
    172168    sortMatchedRules();
    173169
    174     Vector<MatchedRule, 32>& matchedRules = *m_matchedRules;
    175170    if (m_mode == SelectorChecker::Mode::CollectingRules) {
    176         for (const MatchedRule& matchedRule : matchedRules)
     171        for (const MatchedRule& matchedRule : m_matchedRules)
    177172            m_matchedRuleList.append(matchedRule.ruleData->rule());
    178173        return;
     
    180175
    181176    // Now transfer the set of matched rules over to our list of declarations.
    182     for (const MatchedRule& matchedRule : matchedRules) {
     177    for (const MatchedRule& matchedRule : m_matchedRules) {
    183178        if (m_style && matchedRule.ruleData->containsUncommonAttributeSelector())
    184179            m_style->setUnique();
     
    394389void ElementRuleCollector::sortMatchedRules()
    395390{
    396     ASSERT(m_matchedRules);
    397     std::sort(m_matchedRules->begin(), m_matchedRules->end(), compareRules);
     391    std::sort(m_matchedRules.begin(), m_matchedRules.end(), compareRules);
    398392}
    399393
     
    454448    collectMatchingRules(MatchRequest(ruleSet), ruleRange);
    455449
    456     return m_matchedRules && !m_matchedRules->isEmpty();
     450    return !m_matchedRules.isEmpty();
    457451}
    458452
  • trunk/Source/WebCore/css/ElementRuleCollector.h

    r190680 r190842  
    7171    const Vector<RefPtr<StyleRule>>& matchedRuleList() const;
    7272
    73     bool hasMatchedRules() const { return m_matchedRules && !m_matchedRules->isEmpty(); }
     73    bool hasMatchedRules() const { return !m_matchedRules.isEmpty(); }
    7474    void clearMatchedRules();
    7575
     
    104104    bool m_canUseFastReject;
    105105
    106     std::unique_ptr<Vector<MatchedRule, 32>> m_matchedRules;
     106    Vector<MatchedRule, 64> m_matchedRules;
    107107
    108108    // Output.
Note: See TracChangeset for help on using the changeset viewer.