mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 12:25:53 +00:00
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:
parent
74ead075de
commit
6eb7dc59af
@ -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 =
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user