From be6a3393c36ccc1a0cb0d79b116cbe48e169f93b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 19 Oct 2023 09:11:36 -0700 Subject: RemoveUnusedModuleElements: Make exports skip trampolines (#6026) If we export a function that just calls another function, we can export that one instead. Then the one in the middle may be unused, function foo() { return bar(); } export foo; // can be an export of bar This saves a few bytes in rare cases, but probably more important is that it saves the trampoline, so if this is on a hot path, we save a call. Context: emscripten-core/emscripten#20478 (comment) In general this is not needed as inlining helps us out by inlining foo() into the caller (since foo is tiny, that always ends up happening). But exports are a case the inliner cannot handle, so we do it here. --- test/wasm2js/emscripten.2asm.js.opt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'test/wasm2js/emscripten.2asm.js.opt') diff --git a/test/wasm2js/emscripten.2asm.js.opt b/test/wasm2js/emscripten.2asm.js.opt index caef23896..1faf11933 100644 --- a/test/wasm2js/emscripten.2asm.js.opt +++ b/test/wasm2js/emscripten.2asm.js.opt @@ -70,10 +70,6 @@ function asmFunc(imports) { FUNCTION_TABLE[HEAP32[257]](); } - function other() { - main(); - } - function foo() { wasm2js_trap(); } @@ -217,7 +213,7 @@ function asmFunc(imports) { return { "main": main, - "other": other, + "other": main, "__growWasmMemory": __growWasmMemory, "exported": internal, "sub_zero": sub_zero, -- cgit v1.2.3