Changeset 121412 in webkit
- Timestamp:
- Jun 27, 2012 11:29:27 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r121410 r121412 1 2012-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 1 46 2012-06-27 Mary Wu <mary.wu@torchmobile.com.cn> 2 47 -
trunk/Source/WebCore/dom/Document.cpp
r121270 r121412 471 471 , m_sawElementsInKnownNamespaces(false) 472 472 , m_isSrcdocDocument(false) 473 , m_documentRareData(0) 473 474 , m_eventQueue(DocumentEventQueue::create(this)) 474 475 , m_weakReference(DocumentWeakReference::create(this)) … … 607 608 ASSERT(!m_parser || m_parser->refCount() == 1); 608 609 detachParser(); 609 m_document = 0;610 610 611 611 m_renderArena.clear(); … … 650 650 if (hasRareData()) 651 651 clearRareData(); 652 653 m_document = 0; 652 654 653 655 InspectorCounters::decrementCounter(InspectorCounters::DocumentCounter); … … 2008 2010 marginBottom = style->marginBottom().isAuto() ? marginBottom : intValueForLength(style->marginBottom(), width, view); 2009 2011 marginLeft = style->marginLeft().isAuto() ? marginLeft : intValueForLength(style->marginLeft(), width, view); 2012 } 2013 2014 void Document::setDocumentRareData(NodeRareData* rareData) 2015 { 2016 m_documentRareData = rareData; 2010 2017 } 2011 2018 -
trunk/Source/WebCore/dom/Document.h
r121126 r121412 112 112 class NodeFilter; 113 113 class NodeIterator; 114 class NodeRareData; 114 115 class Page; 115 116 class PlatformMouseEvent; … … 433 434 bool isSrcdocDocument() const { return m_isSrcdocDocument; } 434 435 436 NodeRareData* documentRareData() const { return m_documentRareData; }; 437 void setDocumentRareData(NodeRareData*); 438 435 439 StyleResolver* styleResolverIfExists() const { return m_styleResolver.get(); } 436 440 … … 1436 1440 bool m_isSrcdocDocument; 1437 1441 1442 NodeRareData* m_documentRareData; 1443 1438 1444 RefPtr<DocumentEventQueue> m_eventQueue; 1439 1445 -
trunk/Source/WebCore/dom/Node.cpp
r121166 r121412 400 400 #endif 401 401 402 ASSERT(hasRareData() == NodeRareData::rareDataMap().contains(this));403 402 if (hasRareData()) 404 403 clearRareData(); … … 460 459 { 461 460 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; 463 464 } 464 465 … … 467 468 if (hasRareData()) 468 469 return rareData(); 469 470 ASSERT(!NodeRareData::rareDataMap().contains(this)); 470 471 471 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 } 473 480 setFlag(HasRareDataFlag); 474 481 return data; … … 490 497 #endif 491 498 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 } 497 512 clearFlag(HasRareDataFlag); 498 513 }
Note: See TracChangeset
for help on using the changeset viewer.