Changeset 136334 in webkit
- Timestamp:
- Dec 2, 2012 4:03:44 AM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/CMakeLists.txt
r136205 r136334 1146 1146 dom/DocumentParser.cpp 1147 1147 dom/DocumentOrderedMap.cpp 1148 dom/DocumentSharedObjectPool.cpp 1148 1149 dom/DocumentStyleSheetCollection.cpp 1149 1150 dom/DocumentType.cpp -
trunk/Source/WebCore/ChangeLog
r136332 r136334 1 2012-12-02 Andreas Kling <akling@apple.com> 2 3 Keep ElementAttributeData sharing cache open for a while after document parsing finishes. 4 <http://webkit.org/b/103720> 5 6 Reviewed by Antti Koivisto. 7 8 Allow web pages that generate content dynamically to benefit more from the ElementAttributeData sharing 9 cache by keeping it open for 10 seconds after document parsing finishes. This enables elements constructed 10 from HTML fragments to share attribute data with other identical elements. 11 12 Elements created via Document.createElement are still unsupported since we don't know the list of attributes 13 at the time of construction. 14 15 401kB progression on Membuster3. 16 17 Document now holds on to a DocumentSharedObjectPool, accessible via Document::sharedObjectPool(). 18 It is non-null during parsing and for some time afterwards, and can be used to implement additional 19 caches that are not worth holding on to permanently. 20 21 * CMakeLists.txt: 22 * GNUmakefile.list.am: 23 * Target.pri: 24 * WebCore.gypi: 25 * WebCore.xcodeproj/project.pbxproj: 26 * WebCore.vcproj/WebCore.vcproj: 27 28 Add new class DocumentSharedObjectPool. 29 30 * dom/Document.cpp: 31 (WebCore::Document::Document): 32 (WebCore::Document::setParsing): 33 (WebCore::Document::finishedParsing): 34 (WebCore::Document::sharedObjectPoolClearTimerFired): 35 * dom/Document.h: 36 (WebCore::Document::sharedObjectPool): 37 38 Create DocumentSharedObjectPool when parsing starts, kill it on a 10s timer after parsing finishes. 39 40 * dom/DocumentSharedObjectPool.cpp: Added. 41 (ImmutableElementAttributeDataCacheKey): 42 (WebCore::ImmutableElementAttributeDataCacheKey::ImmutableElementAttributeDataCacheKey): 43 (WebCore::ImmutableElementAttributeDataCacheKey::operator!=): 44 (WebCore::ImmutableElementAttributeDataCacheKey::hash): 45 (ImmutableElementAttributeDataCacheEntry): 46 (WebCore::ImmutableElementAttributeDataCacheEntry::ImmutableElementAttributeDataCacheEntry): 47 (WebCore::DocumentSharedObjectPool::cachedImmutableElementAttributeData): 48 (WebCore::DocumentSharedObjectPool::DocumentSharedObjectPool): 49 (WebCore::DocumentSharedObjectPool::~DocumentSharedObjectPool): 50 * dom/DocumentSharedObjectPool.h: Added. 51 (DocumentSharedObjectPool): 52 (WebCore::DocumentSharedObjectPool::create): 53 * dom/Element.cpp: 54 (WebCore::Element::parserSetAttributes): 55 56 Moved the ElementAttributeData cache to DocumentSharedObjectPool. 57 1 58 2012-12-02 John Bauman <jbauman@chromium.org> 2 59 -
trunk/Source/WebCore/GNUmakefile.list.am
r136205 r136334 2758 2758 Source/WebCore/dom/DocumentParser.cpp \ 2759 2759 Source/WebCore/dom/DocumentParser.h \ 2760 Source/WebCore/dom/DocumentSharedObjectPool.cpp \ 2761 Source/WebCore/dom/DocumentSharedObjectPool.h \ 2760 2762 Source/WebCore/dom/DocumentStyleSheetCollection.cpp \ 2761 2763 Source/WebCore/dom/DocumentStyleSheetCollection.h \ -
trunk/Source/WebCore/Target.pri
r136235 r136334 376 376 dom/DocumentOrderedMap.cpp \ 377 377 dom/DocumentParser.cpp \ 378 dom/DocumentSharedObjectPool.cpp \ 378 379 dom/DocumentStyleSheetCollection.cpp \ 379 380 dom/DocumentType.cpp \ … … 1557 1558 dom/DocumentMarkerController.h \ 1558 1559 dom/DocumentOrderedMap.h \ 1560 dom/DocumentSharedObjectPool.h \ 1559 1561 dom/DocumentStyleSheetCollection.h \ 1560 1562 dom/DocumentType.h \ -
trunk/Source/WebCore/WebCore.gypi
r136319 r136334 660 660 'dom/DocumentOrderedMap.h', 661 661 'dom/DocumentParser.h', 662 'dom/DocumentSharedObjectPool.h', 662 663 'dom/DocumentStyleSheetCollection.h', 663 664 'dom/DocumentTiming.h', … … 3807 3808 'dom/DocumentOrderedMap.cpp', 3808 3809 'dom/DocumentParser.cpp', 3810 'dom/DocumentSharedObjectPool.cpp', 3809 3811 'dom/DocumentStyleSheetCollection.cpp', 3810 3812 'dom/DocumentType.cpp', -
trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj
r136205 r136334 50675 50675 </File> 50676 50676 <File 50677 RelativePath="..\dom\DocumentSharedObjectPool.cpp" 50678 > 50679 </File> 50680 <File 50681 RelativePath="..\dom\DocumentSharedObjectPool.h" 50682 > 50683 </File> 50684 <File 50677 50685 RelativePath="..\dom\DocumentStyleSheetCollection.cpp" 50678 50686 > -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r136211 r136334 4627 4627 AD4495F3141FC08900541EDF /* EventListenerMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD4495F1141FC08900541EDF /* EventListenerMap.cpp */; }; 4628 4628 AD4495F4141FC08900541EDF /* EventListenerMap.h in Headers */ = {isa = PBXBuildFile; fileRef = AD4495F2141FC08900541EDF /* EventListenerMap.h */; settings = {ATTRIBUTES = (Private, ); }; }; 4629 AD6E71AC1668899D00320C13 /* DocumentSharedObjectPool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD6E71AA1668899D00320C13 /* DocumentSharedObjectPool.cpp */; }; 4630 AD6E71AD1668899D00320C13 /* DocumentSharedObjectPool.h in Headers */ = {isa = PBXBuildFile; fileRef = AD6E71AB1668899D00320C13 /* DocumentSharedObjectPool.h */; }; 4629 4631 ADDF1AD71257CD9A0003A759 /* RenderSVGPath.h in Headers */ = {isa = PBXBuildFile; fileRef = ADDF1AD51257CD9A0003A759 /* RenderSVGPath.h */; }; 4630 4632 B10B6980140C174000BC1C26 /* WebVTTToken.h in Headers */ = {isa = PBXBuildFile; fileRef = B10B697D140C174000BC1C26 /* WebVTTToken.h */; }; … … 11846 11848 AD4495F1141FC08900541EDF /* EventListenerMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventListenerMap.cpp; sourceTree = "<group>"; }; 11847 11849 AD4495F2141FC08900541EDF /* EventListenerMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventListenerMap.h; sourceTree = "<group>"; }; 11850 AD6E71AA1668899D00320C13 /* DocumentSharedObjectPool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentSharedObjectPool.cpp; sourceTree = "<group>"; }; 11851 AD6E71AB1668899D00320C13 /* DocumentSharedObjectPool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentSharedObjectPool.h; sourceTree = "<group>"; }; 11848 11852 ADDF1AD41257CD9A0003A759 /* RenderSVGPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGPath.cpp; sourceTree = "<group>"; }; 11849 11853 ADDF1AD51257CD9A0003A759 /* RenderSVGPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGPath.h; sourceTree = "<group>"; }; … … 22195 22199 4123E568127B3041000FEEA7 /* WindowEventContext.cpp */, 22196 22200 4123E567127B3041000FEEA7 /* WindowEventContext.h */, 22201 AD6E71AA1668899D00320C13 /* DocumentSharedObjectPool.cpp */, 22202 AD6E71AB1668899D00320C13 /* DocumentSharedObjectPool.h */, 22197 22203 ); 22198 22204 path = dom; … … 25852 25858 447958041643B49A001E0A7F /* ParsedContentType.h in Headers */, 25853 25859 FB2C15C3165D649D0039C9F8 /* CachedSVGDocumentReference.h in Headers */, 25860 AD6E71AD1668899D00320C13 /* DocumentSharedObjectPool.h in Headers */, 25854 25861 31741AAD16636609008A5B7E /* SimulatedClickOptions.h in Headers */, 25855 25862 15B8B7C91652C5220036EF55 /* JSWebKitCSSMixFunctionValue.h in Headers */, … … 28955 28962 1E50084816516AD800B7E098 /* RenderThemeMacShared.mm in Sources */, 28956 28963 CD7E05221651C28200C1201F /* WebCoreAVFResourceLoader.mm in Sources */, 28964 AD6E71AC1668899D00320C13 /* DocumentSharedObjectPool.cpp in Sources */, 28957 28965 447958051643B4B2001E0A7F /* ParsedContentType.cpp in Sources */, 28958 28966 15B8B7C81652C5220036EF55 /* JSWebKitCSSMixFunctionValue.cpp in Sources */, -
trunk/Source/WebCore/dom/DOMAllInOne.cpp
r135671 r136334 67 67 #include "DocumentOrderedMap.cpp" 68 68 #include "DocumentParser.cpp" 69 #include "DocumentSharedObjectPool.cpp" 69 70 #include "DocumentType.cpp" 70 71 #include "Element.cpp" -
trunk/Source/WebCore/dom/Document.cpp
r136277 r136334 56 56 #include "DocumentLoader.h" 57 57 #include "DocumentMarkerController.h" 58 #include "DocumentSharedObjectPool.h" 58 59 #include "DocumentStyleSheetCollection.h" 59 60 #include "DocumentType.h" … … 501 502 , m_visualUpdatesAllowed(true) 502 503 , m_visualUpdatesSuppressionTimer(this, &Document::visualUpdatesSuppressionTimerFired) 504 , m_sharedObjectPoolClearTimer(this, &Document::sharedObjectPoolClearTimerFired) 503 505 #ifndef NDEBUG 504 506 , m_didDispatchViewportPropertiesChanged(false) … … 2492 2494 { 2493 2495 m_bParsing = b; 2496 2497 if (m_bParsing && !m_sharedObjectPool) 2498 m_sharedObjectPool = DocumentSharedObjectPool::create(); 2499 2494 2500 if (!m_bParsing && view()) 2495 2501 view()->scheduleRelayout(); … … 4416 4422 } 4417 4423 4418 // The ElementAttributeData sharing cache is only used during parsing since 4419 // that's when the majority of immutable attribute data will be created. 4420 m_immutableAttributeDataCache.clear(); 4424 // Schedule dropping of the DocumentSharedObjectPool. We keep it alive for a while after parsing finishes 4425 // so that dynamically inserted content can also benefit from sharing optimizations. 4426 // Note that we don't refresh the timer on pool access since that could lead to huge caches being kept 4427 // alive indefinitely by something innocuous like JS setting .innerHTML repeatedly on a timer. 4428 static const int timeToKeepSharedObjectPoolAliveAfterParsingFinishedInSeconds = 10; 4429 m_sharedObjectPoolClearTimer.startOneShot(timeToKeepSharedObjectPoolAliveAfterParsingFinishedInSeconds); 4430 } 4431 4432 void Document::sharedObjectPoolClearTimerFired(Timer<Document>*) 4433 { 4434 m_sharedObjectPool.clear(); 4421 4435 } 4422 4436 … … 5861 5875 } 5862 5876 5863 class ImmutableAttributeDataCacheKey {5864 public:5865 ImmutableAttributeDataCacheKey(const Attribute* attributes, unsigned attributeCount)5866 : m_attributes(attributes)5867 , m_attributeCount(attributeCount)5868 { }5869 5870 bool operator!=(const ImmutableAttributeDataCacheKey& other) const5871 {5872 if (m_attributeCount != other.m_attributeCount)5873 return true;5874 return memcmp(m_attributes, other.m_attributes, sizeof(Attribute) * m_attributeCount);5875 }5876 5877 unsigned hash() const5878 {5879 return StringHasher::hashMemory(m_attributes, m_attributeCount * sizeof(Attribute));5880 }5881 5882 private:5883 const Attribute* m_attributes;5884 unsigned m_attributeCount;5885 };5886 5887 struct ImmutableAttributeDataCacheEntry {5888 ImmutableAttributeDataCacheEntry(const ImmutableAttributeDataCacheKey& k, PassRefPtr<ElementAttributeData> v)5889 : key(k)5890 , value(v)5891 { }5892 5893 ImmutableAttributeDataCacheKey key;5894 RefPtr<ElementAttributeData> value;5895 };5896 5897 PassRefPtr<ElementAttributeData> Document::cachedImmutableAttributeData(const Vector<Attribute>& attributes)5898 {5899 ASSERT(!attributes.isEmpty());5900 5901 ImmutableAttributeDataCacheKey cacheKey(attributes.data(), attributes.size());5902 unsigned cacheHash = cacheKey.hash();5903 5904 ImmutableAttributeDataCache::iterator cacheIterator = m_immutableAttributeDataCache.add(cacheHash, nullptr).iterator;5905 if (cacheIterator->value && cacheIterator->value->key != cacheKey)5906 cacheHash = 0;5907 5908 RefPtr<ElementAttributeData> attributeData;5909 if (cacheHash && cacheIterator->value)5910 attributeData = cacheIterator->value->value;5911 else5912 attributeData = ElementAttributeData::createImmutable(attributes);5913 5914 if (!cacheHash || cacheIterator->value)5915 return attributeData.release();5916 5917 cacheIterator->value = adoptPtr(new ImmutableAttributeDataCacheEntry(ImmutableAttributeDataCacheKey(attributeData->immutableAttributeArray(), attributeData->length()), attributeData));5918 5919 return attributeData.release();5920 }5921 5922 5877 bool Document::haveStylesheetsLoaded() const 5923 5878 { -
trunk/Source/WebCore/dom/Document.h
r136328 r136334 78 78 class DocumentMarkerController; 79 79 class DocumentParser; 80 class DocumentSharedObjectPool; 80 81 class DocumentStyleSheetCollection; 81 82 class DocumentType; 82 83 class DocumentWeakReference; 83 84 class Element; 84 class ElementAttributeData;85 85 class EntityReference; 86 86 class Event; … … 207 207 const int numNodeListInvalidationTypes = InvalidateOnAnyAttrChange + 1; 208 208 209 struct ImmutableAttributeDataCacheEntry;210 typedef HashMap<unsigned, OwnPtr<ImmutableAttributeDataCacheEntry>, AlreadyHashed> ImmutableAttributeDataCache;211 212 209 class Document : public ContainerNode, public TreeScope, public ScriptExecutionContext { 213 210 public: … … 1154 1151 virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE; 1155 1152 1156 PassRefPtr<ElementAttributeData> cachedImmutableAttributeData(const Vector<Attribute>&);1153 DocumentSharedObjectPool* sharedObjectPool() { return m_sharedObjectPool.get(); } 1157 1154 1158 1155 void didRemoveAllPendingStylesheet(); … … 1516 1513 #endif 1517 1514 1518 ImmutableAttributeDataCache m_immutableAttributeDataCache; 1515 void sharedObjectPoolClearTimerFired(Timer<Document>*); 1516 Timer<Document> m_sharedObjectPoolClearTimer; 1517 1518 OwnPtr<DocumentSharedObjectPool> m_sharedObjectPool; 1519 1519 1520 1520 #ifndef NDEBUG -
trunk/Source/WebCore/dom/Element.cpp
r136331 r136334 38 38 #include "Document.h" 39 39 #include "DocumentFragment.h" 40 #include "DocumentSharedObjectPool.h" 40 41 #include "ElementRareData.h" 41 42 #include "ExceptionCode.h" … … 977 978 } 978 979 979 // When the document is in parsing state, we cache immutable ElementAttributeData objects with the980 // input attribute vector as key. (This cache is held by Document.)981 if (!document() || !document()->parsing())980 if (document() && document()->sharedObjectPool()) 981 m_attributeData = document()->sharedObjectPool()->cachedImmutableElementAttributeData(filteredAttributes); 982 else 982 983 m_attributeData = ElementAttributeData::createImmutable(filteredAttributes); 983 else984 m_attributeData = document()->cachedImmutableAttributeData(filteredAttributes);985 984 986 985 // Iterate over the set of attributes we already have on the stack in case
Note: See TracChangeset
for help on using the changeset viewer.