Bug 1381888 - Hard-code the current size factor between the source size and the bytecode size. r=mrbkap

--HG--
extra : rebase_source : 5e2a0735a7d02e414b38ce24ac6b887cb0c7ddbc
This commit is contained in:
Nicolas B. Pierron 2017-07-18 10:09:00 -04:00
parent 74ead075de
commit 6eb7dc59af
4 changed files with 40 additions and 13 deletions

View File

@ -1618,11 +1618,14 @@ ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest)
return rv;
}
size_t len = aRequest->IsSource()
? aRequest->mScriptText.length()
: aRequest->mScriptBytecode.length();
if (!JS::CanCompileOffThread(cx, options, len)) {
return NS_ERROR_FAILURE;
if (aRequest->IsSource()) {
if (!JS::CanCompileOffThread(cx, options, aRequest->mScriptText.length())) {
return NS_ERROR_FAILURE;
}
} else {
if (!JS::CanDecodeOffThread(cx, options, aRequest->mScriptBytecode.length())) {
return NS_ERROR_FAILURE;
}
}
RefPtr<NotifyOffThreadScriptLoadCompletedRunnable> runnable =

View File

@ -4188,11 +4188,16 @@ JS::CompileForNonSyntacticScope(JSContext* cx, const ReadOnlyCompileOptions& opt
return ::Compile(cx, options, ScopeKind::NonSyntactic, filename, script);
}
JS_PUBLIC_API(bool)
JS::CanCompileOffThread(JSContext* cx, const ReadOnlyCompileOptions& options, size_t length)
enum class OffThread {
Compile, Decode,
};
static bool
CanDoOffThread(JSContext* cx, const ReadOnlyCompileOptions& options, size_t length, OffThread what)
{
static const size_t TINY_LENGTH = 5 * 1000;
static const size_t HUGE_LENGTH = 100 * 1000;
static const size_t HUGE_SRC_LENGTH = 100 * 1000;
static const size_t HUGE_BC_LENGTH = 367 * 1000;
// These are heuristics which the caller may choose to ignore (e.g., for
// testing purposes).
@ -4205,13 +4210,29 @@ JS::CanCompileOffThread(JSContext* cx, const ReadOnlyCompileOptions& options, si
// If the parsing task would have to wait for GC to complete, it'll probably
// be faster to just start it synchronously on the active thread unless the
// script is huge.
if (OffThreadParsingMustWaitForGC(cx->runtime()) && length < HUGE_LENGTH)
return false;
if (OffThreadParsingMustWaitForGC(cx->runtime())) {
if (what == OffThread::Compile && length < HUGE_SRC_LENGTH)
return false;
if (what == OffThread::Decode && length < HUGE_BC_LENGTH)
return false;
}
}
return cx->runtime()->canUseParallelParsing() && CanUseExtraThreads();
}
JS_PUBLIC_API(bool)
JS::CanCompileOffThread(JSContext* cx, const ReadOnlyCompileOptions& options, size_t length)
{
return CanDoOffThread(cx, options, length, OffThread::Compile);
}
JS_PUBLIC_API(bool)
JS::CanDecodeOffThread(JSContext* cx, const ReadOnlyCompileOptions& options, size_t length)
{
return CanDoOffThread(cx, options, length, OffThread::Decode);
}
JS_PUBLIC_API(bool)
JS::CompileOffThread(JSContext* cx, const ReadOnlyCompileOptions& options,
const char16_t* chars, size_t length,
@ -4268,7 +4289,7 @@ JS::DecodeOffThreadScript(JSContext* cx, const ReadOnlyCompileOptions& options,
OffThreadCompileCallback callback, void* callbackData)
{
JS::TranscodeRange range(buffer.begin() + cursor, buffer.length() - cursor);
MOZ_ASSERT(CanCompileOffThread(cx, options, range.length()));
MOZ_ASSERT(CanDecodeOffThread(cx, options, range.length()));
return StartOffThreadDecodeScript(cx, options, range, callback, callbackData);
}
@ -4277,7 +4298,7 @@ JS::DecodeOffThreadScript(JSContext* cx, const ReadOnlyCompileOptions& options,
const mozilla::Range<uint8_t>& range /* TranscodeRange& */,
OffThreadCompileCallback callback, void* callbackData)
{
MOZ_ASSERT(CanCompileOffThread(cx, options, range.length()));
MOZ_ASSERT(CanDecodeOffThread(cx, options, range.length()));
return StartOffThreadDecodeScript(cx, options, range, callback, callbackData);
}

View File

@ -4256,6 +4256,9 @@ CompileForNonSyntacticScope(JSContext* cx, const ReadOnlyCompileOptions& options
extern JS_PUBLIC_API(bool)
CanCompileOffThread(JSContext* cx, const ReadOnlyCompileOptions& options, size_t length);
extern JS_PUBLIC_API(bool)
CanDecodeOffThread(JSContext* cx, const ReadOnlyCompileOptions& options, size_t length);
/*
* Off thread compilation control flow.
*

View File

@ -4540,7 +4540,7 @@ OffThreadDecodeScript(JSContext* cx, unsigned argc, Value* vp)
return false;
}
if (!JS::CanCompileOffThread(cx, options, loadLength)) {
if (!JS::CanDecodeOffThread(cx, options, loadLength)) {
JS_ReportErrorASCII(cx, "cannot compile code on worker thread");
return false;
}