[wasm] Speed up generation of module with many functions
Reusing the same {Binary} object (with the same {ArrayBuffer} underneath) speeds up the limits test with 1M functions by a factor of 11x in an optdebug build. R=titzer@chromium.org Change-Id: I36d032d652c66f5b7f5a80399588652d7e3946ec Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1511475 Reviewed-by: Ben Titzer <titzer@chromium.org> Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Cr-Commit-Position: refs/heads/master@{#60127}
This commit is contained in:
parent
10b80795f3
commit
1b7eacdcff
@ -511,6 +511,10 @@ class Binary {
|
||||
return this.buffer = this.buffer.slice(0, this.length);
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.length = 0;
|
||||
}
|
||||
|
||||
emit_u8(val) {
|
||||
this.ensure_space(1);
|
||||
this.buffer[this.length++] = val;
|
||||
@ -1154,7 +1158,9 @@ class WasmModuleBuilder {
|
||||
if (debug) print("emitting code @ " + binary.length);
|
||||
binary.emit_section(kCodeSectionCode, section => {
|
||||
section.emit_u32v(wasm.functions.length);
|
||||
let header = new Binary;
|
||||
for (let func of wasm.functions) {
|
||||
header.reset();
|
||||
// Function body length will be patched later.
|
||||
let local_decls = [];
|
||||
for (let l of func.locals || []) {
|
||||
@ -1184,7 +1190,6 @@ class WasmModuleBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
let header = new Binary;
|
||||
header.emit_u32v(local_decls.length);
|
||||
for (let decl of local_decls) {
|
||||
header.emit_u32v(decl.count);
|
||||
|
Loading…
Reference in New Issue
Block a user