Changeset 121412 in webkit


Ignore:
Timestamp:
Jun 27, 2012 11:29:27 PM (12 years ago)
Author:
haraken@chromium.org
Message:

Performance: Optimize Dromaeo/dom-query.html by caching NodeRareData on Document
https://bugs.webkit.org/show_bug.cgi?id=90059

Reviewed by Ryosuke Niwa.

This patch improves performance of document.getElementsBy*().
e.g. the patch makes Dromaeo/dom-query.html 5.4% faster.

Dromaeo/dom-query.html without the patch (Chromium/Linux):
784714 runs/s, 765947 runs/s, 803109 runs/s, 804450 runs/s

Dromaeo/dom-query.html with the patch (Chromium/Linux):
839245 runs/s, 829867 runs/s, 811032 runs/s, 847486 runs/s

Based on the assumption that document.getElementsByClassName(),
document.getElementsByTagName() and document.getElementsByName()
would be used frequently in the real world, this patch implements
a fast path for Document methods that require to access NodeRareData.
Specifically, this patch caches a pointer to NodeRareData on Document,
by which Document can access NodeRareData without looking up a HashMap.

The only performance concern is the overhead of the isDocumentNode() check
that this patch added to Node::ensureRareData. However, I could not
observe any performance regression caused by the overhead.

No tests. No change in behavior.

  • dom/Document.cpp:

(WebCore::Document::Document):
(WebCore::Document::setCachedRareData): I didn't inline this method,
since the inlining slightly regressed performance for some reason.
(WebCore):

  • dom/Document.h:

(WebCore):
(WebCore::Document::cachedRareData):
(Document):
(~Document): Moved 'm_document = 0' to the tail of the destructor,
since isDocumentNode() has to return true in clearRareData() that is called
in ~Document().

  • dom/Node.cpp:

(WebCore::Node::ensureRareData):
(~Node): Moved the assertion into clearRareData().

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r121410 r121412  
     12012-06-27  Kentaro Hara  <haraken@chromium.org>
     2
     3        Performance: Optimize Dromaeo/dom-query.html by caching NodeRareData on Document
     4        https://bugs.webkit.org/show_bug.cgi?id=90059
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        This patch improves performance of document.getElementsBy*().
     9        e.g. the patch makes Dromaeo/dom-query.html 5.4% faster.
     10
     11        Dromaeo/dom-query.html without the patch (Chromium/Linux):
     12        784714 runs/s, 765947 runs/s, 803109 runs/s, 804450 runs/s
     13
     14        Dromaeo/dom-query.html with the patch (Chromium/Linux):
     15        839245 runs/s, 829867 runs/s, 811032 runs/s, 847486 runs/s
     16
     17        Based on the assumption that document.getElementsByClassName(),
     18        document.getElementsByTagName() and document.getElementsByName()
     19        would be used frequently in the real world, this patch implements
     20        a fast path for Document methods that require to access NodeRareData.
     21        Specifically, this patch caches a pointer to NodeRareData on Document,
     22        by which Document can access NodeRareData without looking up a HashMap.
     23
     24        The only performance concern is the overhead of the isDocumentNode() check
     25        that this patch added to Node::ensureRareData. However, I could not
     26        observe any performance regression caused by the overhead.
     27
     28        No tests. No change in behavior.
     29
     30        * dom/Document.cpp:
     31        (WebCore::Document::Document):
     32        (WebCore::Document::setCachedRareData): I didn't inline this method,
     33        since the inlining slightly regressed performance for some reason.
     34        (WebCore):
     35        * dom/Document.h:
     36        (WebCore):
     37        (WebCore::Document::cachedRareData):
     38        (Document):
     39        (~Document): Moved 'm_document = 0' to the tail of the destructor,
     40        since isDocumentNode() has to return true in clearRareData() that is called
     41        in ~Document().
     42        * dom/Node.cpp:
     43        (WebCore::Node::ensureRareData):
     44        (~Node): Moved the assertion into clearRareData().
     45
    1462012-06-27  Mary Wu  <mary.wu@torchmobile.com.cn>
    247
  • trunk/Source/WebCore/dom/Document.cpp

    r121270 r121412  
    471471    , m_sawElementsInKnownNamespaces(false)
    472472    , m_isSrcdocDocument(false)
     473    , m_documentRareData(0)
    473474    , m_eventQueue(DocumentEventQueue::create(this))
    474475    , m_weakReference(DocumentWeakReference::create(this))
     
    607608    ASSERT(!m_parser || m_parser->refCount() == 1);
    608609    detachParser();
    609     m_document = 0;
    610610
    611611    m_renderArena.clear();
     
    650650    if (hasRareData())
    651651        clearRareData();
     652
     653    m_document = 0;
    652654
    653655    InspectorCounters::decrementCounter(InspectorCounters::DocumentCounter);
     
    20082010    marginBottom = style->marginBottom().isAuto() ? marginBottom : intValueForLength(style->marginBottom(), width, view);
    20092011    marginLeft = style->marginLeft().isAuto() ? marginLeft : intValueForLength(style->marginLeft(), width, view);
     2012}
     2013
     2014void Document::setDocumentRareData(NodeRareData* rareData)
     2015{
     2016    m_documentRareData = rareData;
    20102017}
    20112018
  • trunk/Source/WebCore/dom/Document.h

    r121126 r121412  
    112112class NodeFilter;
    113113class NodeIterator;
     114class NodeRareData;
    114115class Page;
    115116class PlatformMouseEvent;
     
    433434    bool isSrcdocDocument() const { return m_isSrcdocDocument; }
    434435
     436    NodeRareData* documentRareData() const { return m_documentRareData; };
     437    void setDocumentRareData(NodeRareData*);
     438
    435439    StyleResolver* styleResolverIfExists() const { return m_styleResolver.get(); }
    436440
     
    14361440    bool m_isSrcdocDocument;
    14371441
     1442    NodeRareData* m_documentRareData;
     1443
    14381444    RefPtr<DocumentEventQueue> m_eventQueue;
    14391445
  • trunk/Source/WebCore/dom/Node.cpp

    r121166 r121412  
    400400#endif
    401401
    402     ASSERT(hasRareData() == NodeRareData::rareDataMap().contains(this));
    403402    if (hasRareData())
    404403        clearRareData();
     
    460459{
    461460    ASSERT(hasRareData());
    462     return NodeRareData::rareDataFromMap(this);
     461    NodeRareData* data = isDocumentNode() ? static_cast<const Document*>(this)->documentRareData() : NodeRareData::rareDataFromMap(this);
     462    ASSERT(data);
     463    return data;
    463464}
    464465
     
    467468    if (hasRareData())
    468469        return rareData();
    469    
    470     ASSERT(!NodeRareData::rareDataMap().contains(this));
     470
    471471    NodeRareData* data = createRareData().leakPtr();
    472     NodeRareData::rareDataMap().set(this, data);
     472    if (isDocumentNode()) {
     473        // Fast path for a Document. A Document knows a pointer to NodeRareData.
     474        ASSERT(!static_cast<Document*>(this)->documentRareData());
     475        static_cast<Document*>(this)->setDocumentRareData(data);
     476    } else {
     477        ASSERT(!NodeRareData::rareDataMap().contains(this));
     478        NodeRareData::rareDataMap().set(this, data);
     479    }
    473480    setFlag(HasRareDataFlag);
    474481    return data;
     
    490497#endif
    491498
    492     NodeRareData::NodeRareDataMap& dataMap = NodeRareData::rareDataMap();
    493     NodeRareData::NodeRareDataMap::iterator it = dataMap.find(this);
    494     ASSERT(it != dataMap.end());
    495     delete it->second;
    496     dataMap.remove(it);
     499    if (isDocumentNode()) {
     500        Document* document = static_cast<Document*>(this);
     501        NodeRareData* data = document->documentRareData();
     502        ASSERT(data);
     503        delete data;
     504        document->setDocumentRareData(0);
     505    } else {
     506        NodeRareData::NodeRareDataMap& dataMap = NodeRareData::rareDataMap();
     507        NodeRareData::NodeRareDataMap::iterator it = dataMap.find(this);
     508        ASSERT(it != dataMap.end());
     509        delete it->second;
     510        dataMap.remove(it);
     511    }
    497512    clearFlag(HasRareDataFlag);
    498513}
Note: See TracChangeset for help on using the changeset viewer.