Bug 1865929: Apply delazify strategy to small scripts in ScriptLoader. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D194647
This commit is contained in:
@@ -1713,6 +1713,14 @@ class OffThreadCompilationCompleteTask : public Task {
|
|||||||
|
|
||||||
} /* anonymous namespace */
|
} /* anonymous namespace */
|
||||||
|
|
||||||
|
// TODO: This uses the same heuristics and the same threshold as the
|
||||||
|
// JS::CanCompileOffThread / JS::CanDecodeOffThread APIs, but the
|
||||||
|
// heuristics needs to be updated to reflect the change regarding the
|
||||||
|
// Stencil API, and also the thread management on the consumer side
|
||||||
|
// (bug 1846160).
|
||||||
|
static constexpr size_t OffThreadMinimumTextLength = 5 * 1000;
|
||||||
|
static constexpr size_t OffThreadMinimumBytecodeLength = 5 * 1000;
|
||||||
|
|
||||||
nsresult ScriptLoader::AttemptOffThreadScriptCompile(
|
nsresult ScriptLoader::AttemptOffThreadScriptCompile(
|
||||||
ScriptLoadRequest* aRequest, bool* aCouldCompileOut) {
|
ScriptLoadRequest* aRequest, bool* aCouldCompileOut) {
|
||||||
// If speculative parsing is enabled, the request may not be ready to run if
|
// If speculative parsing is enabled, the request may not be ready to run if
|
||||||
@@ -1749,14 +1757,6 @@ nsresult ScriptLoader::AttemptOffThreadScriptCompile(
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This uses the same heuristics and the same threshold as the
|
|
||||||
// JS::CanCompileOffThread / JS::CanDecodeOffThread APIs, but the
|
|
||||||
// heuristics needs to be updated to reflect the change regarding the
|
|
||||||
// Stencil API, and also the thread management on the consumer side
|
|
||||||
// (bug 1846160).
|
|
||||||
static constexpr size_t OffThreadMinimumTextLength = 5 * 1000;
|
|
||||||
static constexpr size_t OffThreadMinimumBytecodeLength = 5 * 1000;
|
|
||||||
|
|
||||||
if (aRequest->IsTextSource()) {
|
if (aRequest->IsTextSource()) {
|
||||||
if (!StaticPrefs::javascript_options_parallel_parsing() ||
|
if (!StaticPrefs::javascript_options_parallel_parsing() ||
|
||||||
aRequest->ScriptTextLength() < OffThreadMinimumTextLength) {
|
aRequest->ScriptTextLength() < OffThreadMinimumTextLength) {
|
||||||
@@ -2048,8 +2048,8 @@ nsresult ScriptLoader::CreateOffThreadTask(
|
|||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
LOG(
|
LOG(
|
||||||
("ScriptLoadRequest (%p): non-on-demand-only Parsing Enabled for "
|
("ScriptLoadRequest (%p): non-on-demand-only (omt) Parsing Enabled "
|
||||||
"url=%s mTotalFullParseSize=%u",
|
"for url=%s mTotalFullParseSize=%u",
|
||||||
aRequest, aRequest->mURI->GetSpecOrDefault().get(),
|
aRequest, aRequest->mURI->GetSpecOrDefault().get(),
|
||||||
mTotalFullParseSize));
|
mTotalFullParseSize));
|
||||||
}
|
}
|
||||||
@@ -2763,6 +2763,23 @@ nsresult ScriptLoader::EvaluateScript(nsIGlobalObject* aGlobalObject,
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply the delazify strategy if the script is small.
|
||||||
|
if (aRequest->IsTextSource() &&
|
||||||
|
aRequest->ScriptTextLength() < OffThreadMinimumTextLength &&
|
||||||
|
ShouldApplyDelazifyStrategy(aRequest)) {
|
||||||
|
ApplyDelazifyStrategy(&options);
|
||||||
|
mTotalFullParseSize +=
|
||||||
|
aRequest->ScriptTextLength() > 0
|
||||||
|
? static_cast<uint32_t>(aRequest->ScriptTextLength())
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
LOG(
|
||||||
|
("ScriptLoadRequest (%p): non-on-demand-only (non-omt) Parsing Enabled "
|
||||||
|
"for url=%s mTotalFullParseSize=%u",
|
||||||
|
aRequest, aRequest->mURI->GetSpecOrDefault().get(),
|
||||||
|
mTotalFullParseSize));
|
||||||
|
}
|
||||||
|
|
||||||
TRACE_FOR_TEST(aRequest->GetScriptLoadContext()->GetScriptElement(),
|
TRACE_FOR_TEST(aRequest->GetScriptLoadContext()->GetScriptElement(),
|
||||||
"scriptloader_execute");
|
"scriptloader_execute");
|
||||||
JS::Rooted<JSObject*> global(cx, aGlobalObject->GetGlobalJSObject());
|
JS::Rooted<JSObject*> global(cx, aGlobalObject->GetGlobalJSObject());
|
||||||
|
|||||||
Reference in New Issue
Block a user