Commit b2177684 authored by clemensh's avatar clemensh Committed by Commit bot

[wasm] Minor optimization for parallel compilation

Skip parallel compilation if less than two functions need to be
compiled, and skip over imported functions instead of adding nullptrs
for them to the compilation_units_ vector.

R=titzer@chromium.org, ahaas@chromium.org

Review-Url: https://codereview.chromium.org/2718053002
Cr-Commit-Position: refs/heads/master@{#43449}
parent 06aeb4ec
...@@ -532,7 +532,7 @@ DEFINE_INT(trace_wasm_text_start, 0, ...@@ -532,7 +532,7 @@ DEFINE_INT(trace_wasm_text_start, 0,
"start function for WASM text generation (inclusive)") "start function for WASM text generation (inclusive)")
DEFINE_INT(trace_wasm_text_end, 0, DEFINE_INT(trace_wasm_text_end, 0,
"end function for WASM text generation (exclusive)") "end function for WASM text generation (exclusive)")
DEFINE_INT(skip_compiling_wasm_funcs, 0, "start compiling at function N") DEFINE_UINT(skip_compiling_wasm_funcs, 0, "start compiling at function N")
DEFINE_BOOL(wasm_break_on_decoder_error, false, DEFINE_BOOL(wasm_break_on_decoder_error, false,
"debug break when wasm decoder encounters an error") "debug break when wasm decoder encounters an error")
DEFINE_BOOL(wasm_loop_assignment_analysis, true, DEFINE_BOOL(wasm_loop_assignment_analysis, true,
......
...@@ -246,25 +246,24 @@ class CompilationHelper { ...@@ -246,25 +246,24 @@ class CompilationHelper {
} }
compiler::WasmCompilationUnit* unit = compilation_units_.at(index); compiler::WasmCompilationUnit* unit = compilation_units_.at(index);
if (unit != nullptr) { unit->ExecuteCompilation();
unit->ExecuteCompilation(); base::LockGuard<base::Mutex> guard(&result_mutex_);
base::LockGuard<base::Mutex> guard(&result_mutex_); executed_units_.push(unit);
executed_units_.push(unit);
}
return true; return true;
} }
void InitializeParallelCompilation(const std::vector<WasmFunction>& functions, void InitializeParallelCompilation(const std::vector<WasmFunction>& functions,
ModuleBytesEnv& module_env, ModuleBytesEnv& module_env,
ErrorThrower* thrower) { ErrorThrower* thrower) {
compilation_units_.reserve(functions.size()); uint32_t start = module_env.module_env.module->num_imported_functions +
for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); FLAG_skip_compiling_wasm_funcs;
++i) { uint32_t num_funcs = static_cast<uint32_t>(functions.size());
uint32_t funcs_to_compile = start > num_funcs ? 0 : num_funcs - start;
compilation_units_.reserve(funcs_to_compile);
for (uint32_t i = start; i < num_funcs; ++i) {
const WasmFunction* func = &functions[i]; const WasmFunction* func = &functions[i];
compilation_units_.push_back( compilation_units_.push_back(new compiler::WasmCompilationUnit(
func->imported ? nullptr thrower, isolate_, &module_env, func, i));
: new compiler::WasmCompilationUnit(
thrower, isolate_, &module_env, func, i));
} }
} }
...@@ -449,7 +448,10 @@ class CompilationHelper { ...@@ -449,7 +448,10 @@ class CompilationHelper {
isolate_->counters()->wasm_functions_per_module()->AddSample( isolate_->counters()->wasm_functions_per_module()->AddSample(
static_cast<int>(module_->functions.size())); static_cast<int>(module_->functions.size()));
CompilationHelper helper(isolate_, module_); CompilationHelper helper(isolate_, module_);
if (!FLAG_trace_wasm_decoder && FLAG_wasm_num_compilation_tasks != 0) { size_t funcs_to_compile =
module_->functions.size() - module_->num_imported_functions;
if (!FLAG_trace_wasm_decoder && FLAG_wasm_num_compilation_tasks != 0 &&
funcs_to_compile > 1) {
// Avoid a race condition by collecting results into a second vector. // Avoid a race condition by collecting results into a second vector.
std::vector<Handle<Code>> results(temp_instance.function_code); std::vector<Handle<Code>> results(temp_instance.function_code);
helper.CompileInParallel(&module_env, results, thrower); helper.CompileInParallel(&module_env, results, thrower);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment