Skip to content

Commit 30097e5

Browse files
authored
Only update functions in optimizeAfterInlining() (#5624)
This saves the work of freeing and allocating for all the other maps. This is a code path that is used by several passes so it showed up in profiling for #5561
1 parent 9ee557a commit 30097e5

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/passes/opt-utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ inline void optimizeAfterInlining(const std::unordered_set<Function*>& funcs,
3737
// save the full list of functions on the side
3838
std::vector<std::unique_ptr<Function>> all;
3939
all.swap(module->functions);
40-
module->updateMaps();
40+
module->updateFunctionsMap();
4141
for (auto& func : funcs) {
4242
module->addFunction(func);
4343
}
@@ -53,7 +53,7 @@ inline void optimizeAfterInlining(const std::unordered_set<Function*>& funcs,
5353
func.release();
5454
}
5555
all.swap(module->functions);
56-
module->updateMaps();
56+
module->updateFunctionsMap();
5757
}
5858

5959
struct FunctionRefReplacer

src/wasm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,6 +2239,7 @@ class Module {
22392239
void removeGlobals(std::function<bool(Global*)> pred);
22402240
void removeTags(std::function<bool(Tag*)> pred);
22412241

2242+
void updateFunctionsMap();
22422243
void updateDataSegmentsMap();
22432244
void updateMaps();
22442245

src/wasm/wasm.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,13 @@ void Module::removeTags(std::function<bool(Tag*)> pred) {
15681568
removeModuleElements(tags, tagsMap, pred);
15691569
}
15701570

1571+
void Module::updateFunctionsMap() {
1572+
functionsMap.clear();
1573+
for (auto& curr : functions) {
1574+
functionsMap[curr->name] = curr.get();
1575+
}
1576+
}
1577+
15711578
void Module::updateDataSegmentsMap() {
15721579
dataSegmentsMap.clear();
15731580
for (auto& curr : dataSegments) {
@@ -1576,10 +1583,7 @@ void Module::updateDataSegmentsMap() {
15761583
}
15771584

15781585
void Module::updateMaps() {
1579-
functionsMap.clear();
1580-
for (auto& curr : functions) {
1581-
functionsMap[curr->name] = curr.get();
1582-
}
1586+
updateFunctionsMap();
15831587
exportsMap.clear();
15841588
for (auto& curr : exports) {
15851589
exportsMap[curr->name] = curr.get();

0 commit comments

Comments
 (0)