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

Unified Diff: third_party/WebKit/Source/core/dom/ScriptLoader.cpp

Issue 2238543002: Instrument parser blocking script execution time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/ScriptLoader.cpp
diff --git a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
index 471a724b2edecac67d544a5c94e8991e2f113b74..dff2446c5a2fae97eece0432697df18e4afcd7fd 100644
--- a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
+++ b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
@@ -28,6 +28,7 @@
#include "core/HTMLNames.h"
#include "core/SVGNames.h"
#include "core/dom/Document.h"
+#include "core/dom/DocumentParserTiming.h"
#include "core/dom/IgnoreDestructiveWriteCountIncrementer.h"
#include "core/dom/ScriptLoaderClient.h"
#include "core/dom/ScriptRunner.h"
@@ -66,7 +67,6 @@ ScriptLoader::ScriptLoader(Element* element, bool parserInserted, bool alreadySt
, m_haveFiredLoad(false)
, m_willBeParserExecuted(false)
, m_readyToBeParserExecuted(false)
- , m_willExecuteInOrder(false)
, m_willExecuteWhenDocumentFinishedParsing(false)
, m_forceAsync(!parserInserted)
, m_createdDuringDocumentWrite(createdDuringDocumentWrite)
@@ -254,19 +254,20 @@ bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, Legacy
m_readyToBeParserExecuted = true;
} else if (client->hasSourceAttribute() && !client->asyncAttributeValue() && !m_forceAsync) {
m_pendingScript = PendingScript::create(m_element, m_resource.get());
- m_willExecuteInOrder = true;
- contextDocument->scriptRunner()->queueScriptForExecution(this, ScriptRunner::IN_ORDER_EXECUTION);
+ m_asyncExecType = ScriptRunner::IN_ORDER_EXECUTION;
+ contextDocument->scriptRunner()->queueScriptForExecution(this, m_asyncExecType.value());
// Note that watchForLoad can immediately call notifyFinished.
m_pendingScript->watchForLoad(this);
} else if (client->hasSourceAttribute()) {
m_pendingScript = PendingScript::create(m_element, m_resource.get());
+ m_asyncExecType = ScriptRunner::ASYNC_EXECUTION;
LocalFrame* frame = m_element->document().frame();
if (frame) {
ScriptState* scriptState = ScriptState::forMainWorld(frame);
if (scriptState)
ScriptStreamer::startStreaming(m_pendingScript.get(), ScriptStreamer::Async, frame->settings(), scriptState, frame->frameScheduler()->loadingTaskRunner());
}
- contextDocument->scriptRunner()->queueScriptForExecution(this, ScriptRunner::ASYNC_EXECUTION);
+ contextDocument->scriptRunner()->queueScriptForExecution(this, m_asyncExecType.value());
// Note that watchForLoad can immediately call notifyFinished.
m_pendingScript->watchForLoad(this);
} else {
@@ -356,6 +357,20 @@ void ScriptLoader::logScriptMimetype(ScriptResource* resource, LocalFrame* frame
bool ScriptLoader::executeScript(const ScriptSourceCode& sourceCode)
{
+ double scriptExecStartTime = monotonicallyIncreasingTime();
+ bool result = doExecuteScript(sourceCode);
+
+ // NOTE: we do not check m_willBeParserExecuted here, since
+ // m_willBeParserExecuted is false for inline scripts, and we want to
+ // include inline script execution time as part of parser blocked script
+ // execution time.
+ if (!m_asyncExecType)
+ DocumentParserTiming::from(m_element->document()).recordParserBlockedOnScriptExecutionDuration(monotonicallyIncreasingTime() - scriptExecStartTime, wasCreatedDuringDocumentWrite());
+ return result;
+}
+
+bool ScriptLoader::doExecuteScript(const ScriptSourceCode& sourceCode)
+{
DCHECK(m_alreadyStarted);
if (sourceCode.isEmpty())
@@ -439,6 +454,7 @@ bool ScriptLoader::executeScript(const ScriptSourceCode& sourceCode)
void ScriptLoader::execute()
{
DCHECK(!m_willBeParserExecuted);
+ DCHECK(m_asyncExecType);
DCHECK(m_pendingScript->resource());
bool errorOccurred = false;
ScriptSourceCode source = m_pendingScript->getSource(KURL(), errorOccurred);
@@ -458,6 +474,7 @@ void ScriptLoader::execute()
void ScriptLoader::notifyFinished(Resource* resource)
{
DCHECK(!m_willBeParserExecuted);
+ DCHECK(m_asyncExecType);
Document* contextDocument = m_element->document().contextDocument();
if (!contextDocument) {
@@ -467,14 +484,13 @@ void ScriptLoader::notifyFinished(Resource* resource)
ASSERT_UNUSED(resource, resource == m_resource);
- ScriptRunner::ExecutionType runOrder = m_willExecuteInOrder ? ScriptRunner::IN_ORDER_EXECUTION : ScriptRunner::ASYNC_EXECUTION;
if (m_resource->errorOccurred()) {
- contextDocument->scriptRunner()->notifyScriptLoadError(this, runOrder);
+ contextDocument->scriptRunner()->notifyScriptLoadError(this, m_asyncExecType.value());
detach();
dispatchErrorEvent();
return;
}
- contextDocument->scriptRunner()->notifyScriptReady(this, runOrder);
+ contextDocument->scriptRunner()->notifyScriptReady(this, m_asyncExecType.value());
m_pendingScript->stopWatchingForLoad();
}

Powered by Google App Engine
This is Rietveld 408576698