Changeset 143279 in webkit
- Timestamp:
- Feb 18, 2013 5:39:12 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r143269 r143279 1 2013-02-18 Geoffrey Garen <ggaren@apple.com> 2 3 Shrank the SourceProvider cache 4 https://bugs.webkit.org/show_bug.cgi?id=110158 5 6 Reviewed by Oliver Hunt. 7 8 New benchmark to show that a minimum size of 16 is better than 64. 9 10 * fast/js/regress/nested-function-parsing-expected.txt: Added. 11 * fast/js/regress/nested-function-parsing.html: Added. 12 * fast/js/regress/script-tests/nested-function-parsing.js: Added. 13 1 14 2013-02-18 Filip Pizlo <fpizlo@apple.com> 2 15 -
trunk/Source/JavaScriptCore/ChangeLog
r143276 r143279 1 2013-02-18 Geoffrey Garen <ggaren@apple.com> 2 3 Shrank the SourceProvider cache 4 https://bugs.webkit.org/show_bug.cgi?id=110158 5 6 Reviewed by Oliver Hunt. 7 8 CodeCache is now our primary source cache, so a long-lived SourceProvider 9 cache is a waste. I measured this as a 10MB Membuster win; with more 10 precise instrumentation, Andreas estimated it as up to 30MB. 11 12 I didn't eliminate the SourceProvider cache because it's still useful 13 in speeding up uncached parsing of scripts with large nested functions 14 (i.e., all scripts). 15 16 * heap/Heap.cpp: 17 (JSC::Heap::collect): Discard all source provider caches after GC. This 18 is a convenient place to do so because it's reasonably soon after initial 19 parsing without being immediate. 20 21 * parser/Parser.cpp: 22 (JSC::::Parser): Updated for interface change: The heap now owns the 23 source provider cache, since most SourceProviders are not expected to 24 have one by default, and the heap is responsible for throwing them away. 25 26 (JSC::::parseInner): No need to update statistics on cache size, since 27 we're going to throw it away no matter what. 28 29 (JSC::::parseFunctionInfo): Reduced the minimum function size to 16. This 30 is a 27% win on a new parsing micro-benchmark I've added. Now that the 31 cache is temporary, we don't have to worry so much about its memory 32 footprint. 33 34 * parser/Parser.h: 35 (Parser): Updated for interface changes. 36 37 * parser/SourceProvider.cpp: 38 (JSC::SourceProvider::SourceProvider): 39 (JSC::SourceProvider::~SourceProvider): 40 * parser/SourceProvider.h: 41 (JSC): 42 (SourceProvider): SourceProvider doesn't own its cache anymore because 43 the cache is temporary. 44 45 * parser/SourceProviderCache.cpp: 46 (JSC::SourceProviderCache::clear): 47 (JSC::SourceProviderCache::add): 48 * parser/SourceProviderCache.h: 49 (JSC::SourceProviderCache::SourceProviderCache): 50 (SourceProviderCache): 51 * parser/SourceProviderCacheItem.h: 52 (SourceProviderCacheItem): No need to update statistics on cache size, 53 since we're going to throw it away no matter what. 54 55 * runtime/JSGlobalData.cpp: 56 (JSC::JSGlobalData::addSourceProviderCache): 57 (JSC): 58 (JSC::JSGlobalData::clearSourceProviderCaches): 59 * runtime/JSGlobalData.h: 60 (JSC): 61 (JSGlobalData): Moved the cache here so it's easier to throw away. 62 1 63 2013-02-18 Filip Pizlo <fpizlo@apple.com> 2 64 -
trunk/Source/JavaScriptCore/heap/Heap.cpp
r141179 r143279 751 751 } 752 752 753 { 754 GCPHASE(DeleteSourceProviderCaches); 755 m_globalData->clearSourceProviderCaches(); 756 } 757 753 758 if (sweepToggle == DoSweep) { 754 759 SamplingRegion samplingRegion("Garbage Collection: Sweeping"); -
trunk/Source/JavaScriptCore/parser/Parser.cpp
r140945 r143279 85 85 m_lexer->setCode(source, m_arena); 86 86 87 m_functionCache = source.provider()->cache();87 m_functionCache = globalData->addSourceProviderCache(source.provider()); 88 88 ScopeRef scope = pushScope(); 89 89 if (parserMode == JSParseFunctionCode) … … 111 111 String parseError = String(); 112 112 113 unsigned oldFunctionCacheSize = m_functionCache ? m_functionCache->byteSize() : 0;114 113 ASTBuilder context(const_cast<JSGlobalData*>(m_globalData), const_cast<SourceCode*>(m_source)); 115 114 if (m_lexer->isReparsing()) … … 127 126 if (scope->shadowsArguments()) 128 127 features |= ShadowsArgumentsFeature; 129 unsigned functionCacheSize = m_functionCache ? m_functionCache->byteSize() : 0;130 if (functionCacheSize != oldFunctionCacheSize)131 m_lexer->sourceProvider()->notifyCacheSizeChanged(functionCacheSize - oldFunctionCacheSize);132 128 133 129 didFinishParsing(sourceElements, context.varDeclarations(), context.funcDeclarations(), features, … … 864 860 // Cache the tokenizer state and the function scope the first time the function is parsed. 865 861 // Any future reparsing can then skip the function. 866 static const int minimumFunctionLengthToCache = 64;862 static const int minimumFunctionLengthToCache = 16; 867 863 OwnPtr<SourceProviderCacheItem> newInfo; 868 864 int functionLength = closeBracePos - openBracePos; … … 880 876 matchOrFail(CLOSEBRACE); 881 877 882 if (newInfo) { 883 unsigned approximateByteSize = newInfo->approximateByteSize(); 884 m_functionCache->add(openBracePos, newInfo.release(), approximateByteSize); 885 } 878 if (newInfo) 879 m_functionCache->add(openBracePos, newInfo.release()); 886 880 887 881 next(); -
trunk/Source/JavaScriptCore/parser/Parser.h
r143147 r143279 909 909 int m_nonTrivialExpressionCount; 910 910 const Identifier* m_lastIdentifier; 911 SourceProviderCache*m_functionCache;911 RefPtr<SourceProviderCache> m_functionCache; 912 912 SourceElements* m_sourceElements; 913 913 ParserArenaData<DeclarationStacks::VarStack>* m_varDeclarations; -
trunk/Source/JavaScriptCore/parser/SourceProvider.cpp
r143147 r143279 27 27 #include "SourceProvider.h" 28 28 29 #include "SourceProviderCache.h"30 31 29 namespace JSC { 32 30 33 SourceProvider::SourceProvider(const String& url, const TextPosition& startPosition , SourceProviderCache* cache)31 SourceProvider::SourceProvider(const String& url, const TextPosition& startPosition) 34 32 : m_url(url) 35 33 , m_startPosition(startPosition) 36 34 , m_validated(false) 37 , m_cache(cache ? cache : new SourceProviderCache)38 , m_cacheOwned(!cache)39 35 { 40 36 } … … 42 38 SourceProvider::~SourceProvider() 43 39 { 44 if (m_cacheOwned)45 delete m_cache;46 40 } 47 41 -
trunk/Source/JavaScriptCore/parser/SourceProvider.h
r143147 r143279 38 38 namespace JSC { 39 39 40 class SourceProviderCache;41 42 40 class SourceProvider : public RefCounted<SourceProvider> { 43 41 public: 44 42 static const intptr_t nullID = 1; 45 43 46 JS_EXPORT_PRIVATE SourceProvider(const String& url, const TextPosition& startPosition , SourceProviderCache* = 0);44 JS_EXPORT_PRIVATE SourceProvider(const String& url, const TextPosition& startPosition); 47 45 48 46 JS_EXPORT_PRIVATE virtual ~SourceProvider(); … … 67 65 void setValid() { m_validated = true; } 68 66 69 SourceProviderCache* cache() const { return m_cache; }70 void notifyCacheSizeChanged(int delta) { if (!m_cacheOwned) cacheSizeChanged(delta); }71 72 67 private: 73 virtual void cacheSizeChanged(int delta) { UNUSED_PARAM(delta); }74 68 75 69 String m_url; 76 70 TextPosition m_startPosition; 77 71 bool m_validated; 78 SourceProviderCache* m_cache;79 bool m_cacheOwned;80 72 }; 81 73 -
trunk/Source/JavaScriptCore/parser/SourceProviderCache.cpp
r104318 r143279 37 37 { 38 38 m_map.clear(); 39 m_contentByteSize = 0;40 39 } 41 40 42 unsigned SourceProviderCache::byteSize() const 43 { 44 return m_contentByteSize + sizeof(*this) + m_map.capacity() * sizeof(SourceProviderCacheItem*); 45 } 46 47 void SourceProviderCache::add(int sourcePosition, PassOwnPtr<SourceProviderCacheItem> item, unsigned size) 41 void SourceProviderCache::add(int sourcePosition, PassOwnPtr<SourceProviderCacheItem> item) 48 42 { 49 43 m_map.add(sourcePosition, item); 50 m_contentByteSize += size;51 44 } 52 45 -
trunk/Source/JavaScriptCore/parser/SourceProviderCache.h
r127484 r143279 31 31 #include <wtf/OwnPtr.h> 32 32 #include <wtf/PassOwnPtr.h> 33 #include <wtf/RefCounted.h> 33 34 34 35 namespace JSC { 35 36 36 class SourceProviderCache {37 class SourceProviderCache : public RefCounted<SourceProviderCache> { 37 38 WTF_MAKE_FAST_ALLOCATED; 38 39 public: 39 SourceProviderCache() : m_contentByteSize(0) {}40 SourceProviderCache() { } 40 41 JS_EXPORT_PRIVATE ~SourceProviderCache(); 41 42 42 43 JS_EXPORT_PRIVATE void clear(); 43 JS_EXPORT_PRIVATE unsigned byteSize() const; 44 void add(int sourcePosition, PassOwnPtr<SourceProviderCacheItem>, unsigned size); 44 void add(int sourcePosition, PassOwnPtr<SourceProviderCacheItem>); 45 45 const SourceProviderCacheItem* get(int sourcePosition) const { return m_map.get(sourcePosition); } 46 46 47 47 private: 48 48 HashMap<int, OwnPtr<SourceProviderCacheItem> > m_map; 49 unsigned m_contentByteSize;50 49 }; 51 50 -
trunk/Source/JavaScriptCore/parser/SourceProviderCacheItem.h
r140945 r143279 56 56 ~SourceProviderCacheItem(); 57 57 58 unsigned approximateByteSize() const59 {60 // The identifiers are uniqued strings so most likely there are few names that actually use any additional memory.61 static const unsigned assumedAverageIdentifierSize = sizeof(StringImpl*) + 2;62 unsigned size = sizeof(*this);63 size += usedVariablesCount * assumedAverageIdentifierSize;64 size += writtenVariablesCount * assumedAverageIdentifierSize;65 return size;66 }67 58 JSToken closeBraceToken() const 68 59 { -
trunk/Source/JavaScriptCore/runtime/JSGlobalData.cpp
r141651 r143279 58 58 #include "RegExpCache.h" 59 59 #include "RegExpObject.h" 60 #include "SourceProviderCache.h" 60 61 #include "StrictEvalActivation.h" 61 62 #include "StrongInlines.h" … … 457 458 } 458 459 460 SourceProviderCache* JSGlobalData::addSourceProviderCache(SourceProvider* sourceProvider) 461 { 462 SourceProviderCacheMap::AddResult addResult = sourceProviderCacheMap.add(sourceProvider, 0); 463 if (addResult.isNewEntry) 464 addResult.iterator->value = adoptRef(new SourceProviderCache); 465 return addResult.iterator->value.get(); 466 } 467 468 void JSGlobalData::clearSourceProviderCaches() 469 { 470 sourceProviderCacheMap.clear(); 471 } 472 459 473 struct StackPreservingRecompiler : public MarkedBlock::VoidFunctor { 460 474 HashSet<FunctionExecutable*> currentlyExecutingFunctions; -
trunk/Source/JavaScriptCore/runtime/JSGlobalData.h
r143247 r143279 83 83 class ParserArena; 84 84 class RegExpCache; 85 class SourceProvider; 86 class SourceProviderCache; 85 87 class Stringifier; 86 88 class Structure; … … 304 306 #endif 305 307 308 SourceProviderCache* addSourceProviderCache(SourceProvider*); 309 void clearSourceProviderCaches(); 310 306 311 PrototypeMap prototypeMap; 307 312 308 313 OwnPtr<ParserArena> parserArena; 314 typedef HashMap<RefPtr<SourceProvider>, RefPtr<SourceProviderCache> > SourceProviderCacheMap; 315 SourceProviderCacheMap sourceProviderCacheMap; 309 316 OwnPtr<Keywords> keywords; 310 317 Interpreter* interpreter; -
trunk/Source/WebCore/ChangeLog
r143272 r143279 1 2013-02-18 Geoffrey Garen <ggaren@apple.com> 2 3 Shrank the SourceProvider cache 4 https://bugs.webkit.org/show_bug.cgi?id=110158 5 6 Reviewed by Oliver Hunt. 7 8 Test: fast/js/regress/nested-function-parsing.html 9 10 No need to keep statistics on cache size, since we're going to throw it 11 away no matter what. 12 13 * WebCore.order: 14 * bindings/js/CachedScriptSourceProvider.h: 15 (CachedScriptSourceProvider): 16 (WebCore::CachedScriptSourceProvider::CachedScriptSourceProvider): 17 * loader/cache/CachedScript.cpp: 18 (WebCore::CachedScript::destroyDecodedData): 19 (WebCore): 20 (WebCore::CachedScript::reportMemoryUsage): 21 * loader/cache/CachedScript.h: 22 (CachedScript): 23 1 24 2013-02-18 peavo@outlook.com <peavo@outlook.com> 2 25 -
trunk/Source/WebCore/WebCore.order
r142977 r143279 4001 4001 __ZN7WebCore14CachedResource12removeClientEPNS_20CachedResourceClientE 4002 4002 __ZNK7WebCore26CachedScriptSourceProvider4dataEv 4003 __ZN7WebCore26CachedScriptSourceProvider16cacheSizeChangedEi4004 __ZN7WebCore12CachedScript30sourceProviderCacheSizeChangedEi4005 4003 __ZN7WebCore17CheckboxInputType6createEPNS_16HTMLInputElementE 4006 4004 __ZNK7WebCore17CheckboxInputType15formControlTypeEv -
trunk/Source/WebCore/bindings/js/CachedScriptSourceProvider.h
r128542 r143279 47 47 const String& source() const { return m_cachedScript->script(); } 48 48 49 virtual void cacheSizeChanged(int delta)50 {51 m_cachedScript->sourceProviderCacheSizeChanged(delta);52 }53 54 49 private: 55 50 CachedScriptSourceProvider(CachedScript* cachedScript) 56 : SourceProvider(cachedScript->response().url(), TextPosition::minimumPosition() , cachedScript->sourceProviderCache())51 : SourceProvider(cachedScript->response().url(), TextPosition::minimumPosition()) 57 52 , m_cachedScript(cachedScript) 58 53 { -
trunk/Source/WebCore/loader/cache/CachedScript.cpp
r143147 r143279 37 37 #include "WebCoreMemoryInstrumentation.h" 38 38 #include <wtf/Vector.h> 39 40 #if USE(JSC)41 #include <parser/SourceProvider.h>42 #include <parser/SourceProviderCache.h>43 #endif44 39 45 40 namespace WebCore { … … 102 97 { 103 98 m_script = String(); 104 unsigned extraSize = 0; 105 #if USE(JSC) 106 if (m_sourceProviderCache && m_clients.isEmpty()) 107 m_sourceProviderCache->clear(); 108 109 extraSize = m_sourceProviderCache ? m_sourceProviderCache->byteSize() : 0; 110 #endif 111 setDecodedSize(extraSize); 99 setDecodedSize(0); 112 100 if (!MemoryCache::shouldMakeResourcePurgeableOnEviction() && isSafeToMakePurgeable()) 113 101 makePurgeable(true); 114 102 } 115 116 #if USE(JSC)117 JSC::SourceProviderCache* CachedScript::sourceProviderCache() const118 {119 if (!m_sourceProviderCache)120 m_sourceProviderCache = adoptPtr(new JSC::SourceProviderCache);121 return m_sourceProviderCache.get();122 }123 124 void CachedScript::sourceProviderCacheSizeChanged(int delta)125 {126 setDecodedSize(decodedSize() + delta);127 }128 #endif129 103 130 104 #if ENABLE(NOSNIFF) … … 141 115 info.addMember(m_script, "script"); 142 116 info.addMember(m_decoder, "decoder"); 143 #if USE(JSC)144 info.addMember(m_sourceProviderCache, "sourceProviderCache");145 #endif146 117 } 147 118 -
trunk/Source/WebCore/loader/cache/CachedScript.h
r142683 r143279 29 29 #include "CachedResource.h" 30 30 31 #if USE(JSC)32 namespace JSC {33 class SourceProviderCache;34 }35 #endif36 37 31 namespace WebCore { 38 32 … … 53 47 54 48 virtual void destroyDecodedData(); 55 #if USE(JSC)56 // Allows JSC to cache additional information about the source.57 JSC::SourceProviderCache* sourceProviderCache() const;58 void sourceProviderCacheSizeChanged(int delta);59 #endif60 49 #if ENABLE(NOSNIFF) 61 50 bool mimeTypeAllowedByNosniff() const; … … 69 58 String m_script; 70 59 RefPtr<TextResourceDecoder> m_decoder; 71 #if USE(JSC)72 mutable OwnPtr<JSC::SourceProviderCache> m_sourceProviderCache;73 #endif74 60 }; 75 61 }
Note: See TracChangeset
for help on using the changeset viewer.