diff options
author | Alon Zakai <azakai@google.com> | 2020-01-23 09:09:02 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-23 09:09:02 -0800 |
commit | d6d565505076581da85e2fc5044a697a8186abf9 (patch) | |
tree | 4d06c0c3fc39b89254a1228fbbe97735e4cad95b | |
parent | cfc581f7d3c629016aa382a7e915f8b0a955fb40 (diff) | |
download | binaryen-d6d565505076581da85e2fc5044a697a8186abf9.tar.gz binaryen-d6d565505076581da85e2fc5044a697a8186abf9.tar.bz2 binaryen-d6d565505076581da85e2fc5044a697a8186abf9.zip |
Initialize the LegalizeJSInterface vector once, not once in each function (#2614)
I missed this in the review of #2451 - this was doing quadratic
work, each function touched the entire array which is the size
of the functions.
This speeds up the pspdfkit testcase from the mailing list from
several minutes (15 on CI; I stopped measuring after 2 minutes
locally) to 5 seconds. I suspect this was not noticed earlier because
that testcase has a very large number of functions, which
hit this issue especially hard.
-rw-r--r-- | src/passes/LegalizeJSInterface.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/passes/LegalizeJSInterface.cpp b/src/passes/LegalizeJSInterface.cpp index 3a28e1745..61f3cfba5 100644 --- a/src/passes/LegalizeJSInterface.cpp +++ b/src/passes/LegalizeJSInterface.cpp @@ -112,6 +112,11 @@ struct LegalizeJSInterface : public Pass { // Gather functions used in 'ref.func'. They should not be removed. std::unordered_map<Name, std::atomic<bool>> usedInRefFunc; + // Fill in unordered_map, as we operate on it in parallel. + for (auto& func : module->functions) { + usedInRefFunc[func->name]; + } + struct RefFuncScanner : public WalkerPass<PostWalker<RefFuncScanner>> { Module& wasm; std::unordered_map<Name, std::atomic<bool>>& usedInRefFunc; @@ -125,12 +130,7 @@ struct LegalizeJSInterface : public Pass { RefFuncScanner( Module& wasm, std::unordered_map<Name, std::atomic<bool>>& usedInRefFunc) - : wasm(wasm), usedInRefFunc(usedInRefFunc) { - // Fill in unordered_map, as we operate on it in parallel - for (auto& func : wasm.functions) { - usedInRefFunc[func->name]; - } - } + : wasm(wasm), usedInRefFunc(usedInRefFunc) {} void visitRefFunc(RefFunc* curr) { usedInRefFunc[curr->func] = true; } }; |