Skip to content

Commit d6d5655

Browse files
authored
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.
1 parent cfc581f commit d6d5655

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/passes/LegalizeJSInterface.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ struct LegalizeJSInterface : public Pass {
112112
// Gather functions used in 'ref.func'. They should not be removed.
113113
std::unordered_map<Name, std::atomic<bool>> usedInRefFunc;
114114

115+
// Fill in unordered_map, as we operate on it in parallel.
116+
for (auto& func : module->functions) {
117+
usedInRefFunc[func->name];
118+
}
119+
115120
struct RefFuncScanner : public WalkerPass<PostWalker<RefFuncScanner>> {
116121
Module& wasm;
117122
std::unordered_map<Name, std::atomic<bool>>& usedInRefFunc;
@@ -125,12 +130,7 @@ struct LegalizeJSInterface : public Pass {
125130
RefFuncScanner(
126131
Module& wasm,
127132
std::unordered_map<Name, std::atomic<bool>>& usedInRefFunc)
128-
: wasm(wasm), usedInRefFunc(usedInRefFunc) {
129-
// Fill in unordered_map, as we operate on it in parallel
130-
for (auto& func : wasm.functions) {
131-
usedInRefFunc[func->name];
132-
}
133-
}
133+
: wasm(wasm), usedInRefFunc(usedInRefFunc) {}
134134

135135
void visitRefFunc(RefFunc* curr) { usedInRefFunc[curr->func] = true; }
136136
};

0 commit comments

Comments
 (0)