[wasm] Make the number of locals available faster
Operations on locals are the most common wasm operations (especially local.get), and just computing the number of locals from the vector shows up with a few percent in the profile. Storing this number separately removes a few percent of execution time from the {DecodeLocalGet} method. R=thibaudm@chromium.org Bug: v8:10576 Change-Id: I9c12842c944e4ad2e602e05838948a33922ff438 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2429950 Reviewed-by: Thibaud Michaud <thibaudm@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#70148}
This commit is contained in:
parent
f50d8c7840
commit
65c15f4fe3
@ -1002,7 +1002,8 @@ class WasmDecoder : public Decoder {
|
||||
Zone* zone() const { return local_types_.get_allocator().zone(); }
|
||||
|
||||
uint32_t num_locals() const {
|
||||
return static_cast<uint32_t>(local_types_.size());
|
||||
DCHECK_EQ(num_locals_, local_types_.size());
|
||||
return num_locals_;
|
||||
}
|
||||
|
||||
ValueType local_type(uint32_t index) const { return local_types_[index]; }
|
||||
@ -1011,12 +1012,13 @@ class WasmDecoder : public Decoder {
|
||||
DCHECK_NOT_NULL(sig_);
|
||||
DCHECK_EQ(0, this->local_types_.size());
|
||||
local_types_.assign(sig_->parameters().begin(), sig_->parameters().end());
|
||||
num_locals_ = static_cast<uint32_t>(sig_->parameters().size());
|
||||
}
|
||||
|
||||
// Decodes local definitions in the current decoder.
|
||||
// Returns true iff locals are found.
|
||||
// Writes the total length of decoded locals in 'total_length'.
|
||||
// If insert_postion is present, the decoded locals will be inserted into the
|
||||
// If insert_position is present, the decoded locals will be inserted into the
|
||||
// 'local_types_' of this decoder. Otherwise, this function is used just to
|
||||
// check validity and determine the encoding length of the locals in bytes.
|
||||
// The decoder's pc is not advanced. If no locals are found (i.e., no
|
||||
@ -1072,6 +1074,7 @@ class WasmDecoder : public Decoder {
|
||||
// Move the insertion iterator to the end of the newly inserted locals.
|
||||
insert_iterator =
|
||||
local_types_.insert(insert_iterator, count, type) + count;
|
||||
num_locals_ += count;
|
||||
}
|
||||
}
|
||||
DCHECK(ok());
|
||||
@ -1899,6 +1902,10 @@ class WasmDecoder : public Decoder {
|
||||
// needed (see {zone()} accessor below).
|
||||
ZoneVector<ValueType> local_types_;
|
||||
|
||||
// Cached value, for speed (yes, it's measurably faster to load this value
|
||||
// than to load the start and end pointer from a vector, subtract and shift).
|
||||
uint32_t num_locals_ = 0;
|
||||
|
||||
const WasmModule* module_;
|
||||
const WasmFeatures enabled_;
|
||||
WasmFeatures* detected_;
|
||||
@ -2434,6 +2441,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
|
||||
if (c->is_let()) {
|
||||
this->local_types_.erase(this->local_types_.begin(),
|
||||
this->local_types_.begin() + c->locals_count);
|
||||
this->num_locals_ -= c->locals_count;
|
||||
CALL_INTERFACE_IF_REACHABLE(DeallocateLocals, c->locals_count);
|
||||
}
|
||||
if (!TypeCheckFallThru()) return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user