Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: Source/core/html/parser/HTMLScriptRunner.cpp

Issue 551333002: Fix WebCore.Scripts.ParserBlocking.TimeBetweenLoadedAndCompiled (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebased Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/parser/HTMLScriptRunner.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 namespace blink { 43 namespace blink {
44 44
45 using namespace HTMLNames; 45 using namespace HTMLNames;
46 46
47 HTMLScriptRunner::HTMLScriptRunner(Document* document, HTMLScriptRunnerHost* hos t) 47 HTMLScriptRunner::HTMLScriptRunner(Document* document, HTMLScriptRunnerHost* hos t)
48 : m_document(document) 48 : m_document(document)
49 , m_host(host) 49 , m_host(host)
50 , m_scriptNestingLevel(0) 50 , m_scriptNestingLevel(0)
51 , m_hasScriptsWaitingForResources(false) 51 , m_hasScriptsWaitingForResources(false)
52 , m_parserBlockingScriptAlreadyLoaded(false)
52 { 53 {
53 ASSERT(m_host); 54 ASSERT(m_host);
54 } 55 }
55 56
56 HTMLScriptRunner::~HTMLScriptRunner() 57 HTMLScriptRunner::~HTMLScriptRunner()
57 { 58 {
58 #if ENABLE(OILPAN) 59 #if ENABLE(OILPAN)
59 // If the document is destructed without having explicitly 60 // If the document is destructed without having explicitly
60 // detached the parser (and this script runner object), perform 61 // detached the parser (and this script runner object), perform
61 // detach steps now. This will happen if the Document, the parser 62 // detach steps now. This will happen if the Document, the parser
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 ASSERT(m_document->isScriptExecutionReady()); 119 ASSERT(m_document->isScriptExecutionReady());
119 ASSERT(isPendingScriptReady(m_parserBlockingScript)); 120 ASSERT(isPendingScriptReady(m_parserBlockingScript));
120 121
121 InsertionPointRecord insertionPointRecord(m_host->inputStream()); 122 InsertionPointRecord insertionPointRecord(m_host->inputStream());
122 executePendingScriptAndDispatchEvent(m_parserBlockingScript, PendingScriptBl ockingParser); 123 executePendingScriptAndDispatchEvent(m_parserBlockingScript, PendingScriptBl ockingParser);
123 } 124 }
124 125
125 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendi ngScript, PendingScriptType pendingScriptType) 126 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendi ngScript, PendingScriptType pendingScriptType)
126 { 127 {
127 bool errorOccurred = false; 128 bool errorOccurred = false;
129 double loadFinishTime = pendingScript.resource() ? pendingScript.resource()- >loadFinishTime() : 0;
128 ScriptSourceCode sourceCode = pendingScript.getSource(documentURLForScriptEx ecution(m_document), errorOccurred); 130 ScriptSourceCode sourceCode = pendingScript.getSource(documentURLForScriptEx ecution(m_document), errorOccurred);
129 131
130 // Stop watching loads before executeScript to prevent recursion if the scri pt reloads itself. 132 // Stop watching loads before executeScript to prevent recursion if the scri pt reloads itself.
131 pendingScript.stopWatchingForLoad(this); 133 pendingScript.stopWatchingForLoad(this);
132 134
133 if (!isExecutingScript()) { 135 if (!isExecutingScript()) {
134 Microtask::performCheckpoint(); 136 Microtask::performCheckpoint();
135 if (pendingScriptType == PendingScriptBlockingParser) { 137 if (pendingScriptType == PendingScriptBlockingParser) {
136 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionRead y(); 138 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionRead y();
137 // The parser cannot be unblocked as a microtask requested another r esource 139 // The parser cannot be unblocked as a microtask requested another r esource
138 if (m_hasScriptsWaitingForResources) 140 if (m_hasScriptsWaitingForResources)
139 return; 141 return;
140 } 142 }
141 } 143 }
142 144
143 // Clear the pending script before possible rentrancy from executeScript() 145 // Clear the pending script before possible rentrancy from executeScript()
144 RefPtrWillBeRawPtr<Element> element = pendingScript.releaseElementAndClear() ; 146 RefPtrWillBeRawPtr<Element> element = pendingScript.releaseElementAndClear() ;
147 double compilationFinishTime = 0;
145 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element.get())) { 148 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element.get())) {
146 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); 149 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel);
147 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem enter(m_document); 150 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem enter(m_document);
148 if (errorOccurred) 151 if (errorOccurred)
149 scriptLoader->dispatchErrorEvent(); 152 scriptLoader->dispatchErrorEvent();
150 else { 153 else {
151 ASSERT(isExecutingScript()); 154 ASSERT(isExecutingScript());
152 scriptLoader->executeScript(sourceCode); 155 scriptLoader->executeScript(sourceCode, &compilationFinishTime);
153 element->dispatchEvent(createScriptLoadEvent()); 156 element->dispatchEvent(createScriptLoadEvent());
154 } 157 }
155 } 158 }
156 if (sourceCode.resource()) { 159 // The exact value doesn't matter; valid time stamps are much bigger than th is value.
157 double timeBetweenLoadedAndCompiledMs = (WTF::monotonicallyIncreasingTim e() - sourceCode.resource()->loadFinishTime()) * 1000; 160 const double epsilon = 1;
158 const char* histogramName = pendingScriptType == PendingScriptBlockingPa rser ? "WebCore.Scripts.ParsingBlocking.TimeBetweenLoadedAndCompiled" : "WebCore .Scripts.Deferred.TimeBetweenLoadedAndCompiled"; 161 if (pendingScriptType == PendingScriptBlockingParser && !m_parserBlockingScr iptAlreadyLoaded && compilationFinishTime > epsilon && loadFinishTime > epsilon) {
159 blink::Platform::current()->histogramCustomCounts(histogramName, timeBet weenLoadedAndCompiledMs, 0, 10000, 50); 162 blink::Platform::current()->histogramCustomCounts("WebCore.Scripts.Parsi ngBlocking.TimeBetweenLoadedAndCompiled", (compilationFinishTime - loadFinishTim e) * 1000, 0, 10000, 50);
160 } 163 }
161 164
162 ASSERT(!isExecutingScript()); 165 ASSERT(!isExecutingScript());
163 } 166 }
164 167
165 void HTMLScriptRunner::notifyFinished(Resource* cachedResource) 168 void HTMLScriptRunner::notifyFinished(Resource* cachedResource)
166 { 169 {
167 m_host->notifyScriptLoaded(cachedResource); 170 m_host->notifyScriptLoaded(cachedResource);
168 } 171 }
169 172
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 return true; 243 return true;
241 } 244 }
242 245
243 void HTMLScriptRunner::requestParsingBlockingScript(Element* element) 246 void HTMLScriptRunner::requestParsingBlockingScript(Element* element)
244 { 247 {
245 if (!requestPendingScript(m_parserBlockingScript, element)) 248 if (!requestPendingScript(m_parserBlockingScript, element))
246 return; 249 return;
247 250
248 ASSERT(m_parserBlockingScript.resource()); 251 ASSERT(m_parserBlockingScript.resource());
249 252
250 blink::Platform::current()->histogramEnumeration("WebCore.Scripts.ParsingBlo cking.AlreadyLoaded", m_parserBlockingScript.resource()->isLoaded() ? 1 : 0, 2); 253 m_parserBlockingScriptAlreadyLoaded = m_parserBlockingScript.resource()->isL oaded();
254 blink::Platform::current()->histogramEnumeration("WebCore.Scripts.ParsingBlo cking.AlreadyLoaded", m_parserBlockingScriptAlreadyLoaded ? 1 : 0, 2);
251 // We only care about a load callback if resource is not already 255 // We only care about a load callback if resource is not already
252 // in the cache. Callers will attempt to run the m_parserBlockingScript 256 // in the cache. Callers will attempt to run the m_parserBlockingScript
253 // if possible before returning control to the parser. 257 // if possible before returning control to the parser.
254 if (!m_parserBlockingScript.resource()->isLoaded()) 258 if (!m_parserBlockingScriptAlreadyLoaded)
255 m_parserBlockingScript.watchForLoad(this); 259 m_parserBlockingScript.watchForLoad(this);
256 } 260 }
257 261
258 void HTMLScriptRunner::requestDeferredScript(Element* element) 262 void HTMLScriptRunner::requestDeferredScript(Element* element)
259 { 263 {
260 PendingScript pendingScript; 264 PendingScript pendingScript;
261 if (!requestPendingScript(pendingScript, element)) 265 if (!requestPendingScript(pendingScript, element))
262 return; 266 return;
263 267
264 ASSERT(pendingScript.resource()); 268 ASSERT(pendingScript.resource());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 331
328 void HTMLScriptRunner::trace(Visitor* visitor) 332 void HTMLScriptRunner::trace(Visitor* visitor)
329 { 333 {
330 visitor->trace(m_document); 334 visitor->trace(m_document);
331 visitor->trace(m_host); 335 visitor->trace(m_host);
332 visitor->trace(m_parserBlockingScript); 336 visitor->trace(m_parserBlockingScript);
333 visitor->trace(m_scriptsToExecuteAfterParsing); 337 visitor->trace(m_scriptsToExecuteAfterParsing);
334 } 338 }
335 339
336 } 340 }
OLDNEW
« no previous file with comments | « Source/core/html/parser/HTMLScriptRunner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698