Commit 1b7eacdc authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[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/+/1511475Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60127}
parent 10b80795
......@@ -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);
......
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