Commit e8f98899 authored by Mircea Trofin's avatar Mircea Trofin Committed by Commit Bot

[wasm] Faster Instantiate by avoiding redundant default code init

The compiler patches all call sites with a default code object value.
We used to populate a vector with that value. Turns out that avoiding
having that vector measurably reduces instantiation time.

Bug: 
Change-Id: I2c843210a2ab24541f370b5493c3cbb555149e1a
Reviewed-on: https://chromium-review.googlesource.com/609480
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: 's avatarBrad Nelson <bradnelson@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47296}
parent 468d5faa
......@@ -293,7 +293,7 @@ class V8_EXPORT_PRIVATE ModuleEnv {
: module_(module),
function_tables_(module->function_tables.size()),
signature_tables_(module->function_tables.size()),
function_code_(module->functions.size(), default_function_code),
default_function_code_(default_function_code),
mem_size_(module->initial_pages * WasmModule::kPageSize) {}
WasmModule* module() const { return module_; }
......@@ -364,7 +364,10 @@ class V8_EXPORT_PRIVATE ModuleEnv {
bool is_wasm() const { return module_->is_wasm(); }
Handle<Code> GetFunctionCode(uint32_t index) const {
return function_code_[index];
if (index < function_code_.size()) {
return function_code_[index];
}
return default_function_code_;
}
// TODO(mtrofin): this is async compilation-specific. Move this out.
......@@ -378,6 +381,7 @@ class V8_EXPORT_PRIVATE ModuleEnv {
for (auto& code : function_code_) {
code = handle(*code, isolate);
}
default_function_code_ = handle(*default_function_code_, isolate);
}
// Intentionally set a memory size that may not conform to
......@@ -397,12 +401,12 @@ class V8_EXPORT_PRIVATE ModuleEnv {
std::vector<Handle<FixedArray>> function_tables_;
// indirect signature tables.
std::vector<Handle<FixedArray>> signature_tables_;
// TODO(mtrofin): this should be a Handle<Code>, not a vector,
// however, cctest currently builds up modules in a non-production
// standard way. We should address that first.
// a user of the compiler may choose to pre-populate this
// with code objects to be used instead of the default
std::vector<Handle<Code>> function_code_;
private:
Handle<Code> default_function_code_;
// size of the linear memory.
uint32_t mem_size_ = 0;
......
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