Bug 1382329: Part 2 - Eagerly encode scripts for the startup cache. r=erahm,nbp

MozReview-Commit-ID: JqCqQZ2rO2z

--HG--
extra : rebase_source : 14874cae551f10f091461c9e9b1d9a48c99afc2b
This commit is contained in:
Kris Maglione 2017-07-19 12:44:17 -07:00
Родитель 4c48c5dab8
Коммит d3ebec307a
1 изменённых файлов: 17 добавлений и 2 удалений

Просмотреть файл

@ -548,8 +548,6 @@ ScriptPreloader::PrepareCacheWriteInternal()
if (!script->mSize && !script->XDREncode(jsapi.cx())) {
script.Remove();
} else {
script->mSize = script->Range().length();
}
}
@ -714,6 +712,21 @@ ScriptPreloader::NoteScript(const nsCString& url, const nsCString& cachePath,
script->mReadyToExecute = true;
}
// If we don't already have bytecode for this script, and it doesn't already
// exist in the child cache, encode it now, before it's ever executed.
//
// Ideally, we would like to do the encoding lazily, during idle slices.
// There are subtle issues with encoding scripts which have already been
// executed, though, which makes that somewhat risky. So until that
// situation is improved, and thoroughly tested, we need to encode eagerly.
//
// (See also the TranscodeResult_Failure_RunOnceNotSupported failure case in
// js::XDRScript)
if (!script->mSize && !(mChildCache && mChildCache->mScripts.Get(cachePath))) {
AutoSafeJSAPI jsapi;
Unused << script->XDREncode(jsapi.cx());
}
script->UpdateLoadTime(TimeStamp::Now());
script->mProcessTypes += CurrentProcessType();
}
@ -991,8 +1004,10 @@ ScriptPreloader::CachedScript::XDREncode(JSContext* cx)
JS::TranscodeResult code = JS::EncodeScript(cx, Buffer(), jsscript);
if (code == JS::TranscodeResult_Ok) {
mXDRRange.emplace(Buffer().begin(), Buffer().length());
mSize = Range().length();
return true;
}
mXDRData.destroy();
JS_ClearPendingException(cx);
return false;
}