Skip to content

Commit

Permalink
Initialize the LegalizeJSInterface vector once, not once in each func…
Browse files Browse the repository at this point in the history
…tion (#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.
  • Loading branch information
kripken authored Jan 23, 2020
1 parent cfc581f commit d6d5655
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/passes/LegalizeJSInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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; }
};
Expand Down

0 comments on commit d6d5655

Please sign in to comment.