Bug 1776205 - Set the delazify option in all ScriptLoader code paths. r=arai
This patch move the ShouldApplyDelazificationStartegy as well as the ApplyDelazificationStrategy under FillCompileOptionsForRequest. As not all delazification strategies are capable of handling modules yet (Bug 1760334), and do not apply to cached-stencil, we have to add extra filters to prevent ShouldApplyDelazificationStrategy to access custom delazification mode. Differential Revision: https://phabricator.services.mozilla.com/D150118
This commit is contained in:
@@ -1672,20 +1672,6 @@ nsresult ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest,
|
||||
} else {
|
||||
MOZ_ASSERT(aRequest->IsTextSource());
|
||||
|
||||
if (ShouldApplyDelazifyStrategy(aRequest)) {
|
||||
ApplyDelazifyStrategy(&options);
|
||||
mTotalFullParseSize +=
|
||||
aRequest->ScriptTextLength() > 0
|
||||
? static_cast<uint32_t>(aRequest->ScriptTextLength())
|
||||
: 0;
|
||||
|
||||
LOG(
|
||||
("ScriptLoadRequest (%p): non-on-demand-only Parsing Enabled for "
|
||||
"url=%s mTotalFullParseSize=%u",
|
||||
aRequest, aRequest->mURI->GetSpecOrDefault().get(),
|
||||
mTotalFullParseSize));
|
||||
}
|
||||
|
||||
MaybeSourceText maybeSource;
|
||||
nsresult rv = aRequest->GetScriptSource(cx, &maybeSource);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@@ -2013,6 +1999,20 @@ nsresult ScriptLoader::FillCompileOptionsForRequest(
|
||||
|
||||
aOptions->allocateInstantiationStorage = true;
|
||||
|
||||
if (ShouldApplyDelazifyStrategy(aRequest)) {
|
||||
ApplyDelazifyStrategy(aOptions);
|
||||
mTotalFullParseSize +=
|
||||
aRequest->ScriptTextLength() > 0
|
||||
? static_cast<uint32_t>(aRequest->ScriptTextLength())
|
||||
: 0;
|
||||
} else {
|
||||
// If we cannot apply the delazification strategy set in the preference, due
|
||||
// to failure of the preconditions, then we default to the strategy which
|
||||
// minimize the memory impact at runtime.
|
||||
aOptions->setEagerDelazificationStrategy(
|
||||
JS::DelazificationOption::OnDemandOnly);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -3241,6 +3241,26 @@ static bool IsInternalURIScheme(nsIURI* uri) {
|
||||
|
||||
bool ScriptLoader::ShouldApplyDelazifyStrategy(ScriptLoadRequest* aRequest) {
|
||||
// Full parse everything if negative.
|
||||
if (!aRequest->IsTextSource()) {
|
||||
// Delazification strategy is only used while processing source input, as
|
||||
// the bytecode cache already contains delazified functions.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (aRequest->IsModuleRequest()) {
|
||||
// Module do not yet support concurrent off-thread delazification.
|
||||
// (see Bug 1760334)
|
||||
return false;
|
||||
}
|
||||
|
||||
auto logEnabled = MakeScopeExit([&] {
|
||||
LOG(
|
||||
("ScriptLoadRequest (%p): non-on-demand-only Parsing Enabled for "
|
||||
"url=%s mTotalFullParseSize=%u",
|
||||
aRequest, aRequest->mURI->GetSpecOrDefault().get(),
|
||||
mTotalFullParseSize));
|
||||
});
|
||||
|
||||
if (StaticPrefs::dom_script_loader_delazification_max_size() < 0) {
|
||||
return true;
|
||||
}
|
||||
@@ -3248,6 +3268,7 @@ bool ScriptLoader::ShouldApplyDelazifyStrategy(ScriptLoadRequest* aRequest) {
|
||||
// Be conservative on machines with 2GB or less of memory.
|
||||
if (PhysicalSizeOfMemoryInGB() <=
|
||||
StaticPrefs::dom_script_loader_delazification_min_mem()) {
|
||||
logEnabled.release();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -3262,6 +3283,7 @@ bool ScriptLoader::ShouldApplyDelazifyStrategy(ScriptLoadRequest* aRequest) {
|
||||
return true;
|
||||
}
|
||||
|
||||
logEnabled.release();
|
||||
if (LOG_ENABLED()) {
|
||||
nsCString url = aRequest->mURI->GetSpecOrDefault();
|
||||
LOG(
|
||||
|
||||
Reference in New Issue
Block a user