From 418804035056bcd133ff5e292bf645d5d26d8d0d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 22 Mar 2021 16:33:37 -0700 Subject: wasm-emscripten-finalize: Do not skip the start function body (#3714) When we can skip function bodies, we still need to parse the start function for the pthreads case, see details in the comments. This still gives us 99% of the speedup as the start function is just 1 function and it's not that big, so with this we return to full speed after the reversion in #3705 --- src/wasm/wasm-binary.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/wasm/wasm-binary.cpp') diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 37fa1ab78..6cb837296 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -2141,7 +2141,14 @@ void WasmBinaryBuilder::readFunctions() { assert(controlFlowStack.empty()); assert(letStack.empty()); assert(depth == 0); - if (!skipFunctionBodies) { + // Even if we are skipping function bodies we need to not skip the start + // function. That contains important code for wasm-emscripten-finalize in + // the form of pthread-related segment initializations. As this is just + // one function, it doesn't add significant time, so the optimization of + // skipping bodies is still very useful. + auto currFunctionIndex = functionImports.size() + functions.size(); + bool isStart = startIndex == currFunctionIndex; + if (!skipFunctionBodies || isStart) { func->body = getBlockOrSingleton(func->sig.results); } else { // When skipping the function body we need to put something valid in -- cgit v1.2.3