From 30097e5da0a99fa42dac1af1efeb435c5f15e1f0 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 5 Apr 2023 12:24:30 -0700 Subject: 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 --- src/passes/opt-utils.h | 4 ++-- src/wasm.h | 1 + src/wasm/wasm.cpp | 12 ++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/passes/opt-utils.h b/src/passes/opt-utils.h index 9bc81c382..1945167b0 100644 --- a/src/passes/opt-utils.h +++ b/src/passes/opt-utils.h @@ -37,7 +37,7 @@ inline void optimizeAfterInlining(const std::unordered_set& funcs, // save the full list of functions on the side std::vector> all; all.swap(module->functions); - module->updateMaps(); + module->updateFunctionsMap(); for (auto& func : funcs) { module->addFunction(func); } @@ -53,7 +53,7 @@ inline void optimizeAfterInlining(const std::unordered_set& funcs, func.release(); } all.swap(module->functions); - module->updateMaps(); + module->updateFunctionsMap(); } struct FunctionRefReplacer diff --git a/src/wasm.h b/src/wasm.h index d776ec9aa..dd989602a 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -2239,6 +2239,7 @@ public: void removeGlobals(std::function pred); void removeTags(std::function pred); + void updateFunctionsMap(); void updateDataSegmentsMap(); void updateMaps(); diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 54e9dd142..b21c1849a 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -1568,6 +1568,13 @@ void Module::removeTags(std::function pred) { removeModuleElements(tags, tagsMap, pred); } +void Module::updateFunctionsMap() { + functionsMap.clear(); + for (auto& curr : functions) { + functionsMap[curr->name] = curr.get(); + } +} + void Module::updateDataSegmentsMap() { dataSegmentsMap.clear(); for (auto& curr : dataSegments) { @@ -1576,10 +1583,7 @@ void Module::updateDataSegmentsMap() { } void Module::updateMaps() { - functionsMap.clear(); - for (auto& curr : functions) { - functionsMap[curr->name] = curr.get(); - } + updateFunctionsMap(); exportsMap.clear(); for (auto& curr : exports) { exportsMap[curr->name] = curr.get(); -- cgit v1.2.3