From ce153ac5350ffca613ed80c777bcce9a0343e944 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Thu, 28 Aug 2025 14:14:07 -0700 Subject: [PATCH] Remove the `wasm-instantate` run dependency. NFC Instead we can just delay the `run` call until after createWasm is resolved. This results in a nice code size saving. --- src/lib/libbrowser.js | 2 +- src/postamble.js | 5 +- src/preamble.js | 6 -- test/code_size/test_codesize_cxx_ctors1.json | 8 +- test/code_size/test_codesize_cxx_ctors2.json | 8 +- test/code_size/test_codesize_cxx_except.json | 8 +- .../test_codesize_cxx_except_wasm.json | 8 +- .../test_codesize_cxx_except_wasm_legacy.json | 8 +- test/code_size/test_codesize_cxx_lto.json | 8 +- test/code_size/test_codesize_cxx_mangle.json | 8 +- .../code_size/test_codesize_cxx_noexcept.json | 8 +- test/code_size/test_codesize_cxx_wasmfs.json | 8 +- .../code_size/test_codesize_file_preload.json | 8 +- test/code_size/test_codesize_files_js_fs.json | 8 +- .../code_size/test_codesize_files_wasmfs.json | 8 +- test/code_size/test_codesize_hello_O0.json | 8 +- test/code_size/test_codesize_hello_O1.json | 8 +- test/code_size/test_codesize_hello_O2.json | 8 +- test/code_size/test_codesize_hello_O3.json | 8 +- test/code_size/test_codesize_hello_Os.json | 8 +- test/code_size/test_codesize_hello_Oz.json | 8 +- .../code_size/test_codesize_hello_dylink.json | 8 +- .../test_codesize_hello_export_nothing.json | 8 +- .../test_codesize_hello_single_file.json | 4 +- .../code_size/test_codesize_hello_wasmfs.json | 8 +- .../test_codesize_libcxxabi_message_O3.json | 8 +- ...esize_libcxxabi_message_O3_standalone.json | 8 +- test/code_size/test_codesize_mem_O3.json | 8 +- test/code_size/test_codesize_mem_O3_grow.json | 8 +- .../test_codesize_mem_O3_grow_standalone.json | 8 +- .../test_codesize_mem_O3_standalone.json | 8 +- .../test_codesize_mem_O3_standalone_lib.json | 8 +- .../test_codesize_mem_O3_standalone_narg.json | 8 +- ..._codesize_mem_O3_standalone_narg_flto.json | 8 +- test/code_size/test_codesize_minimal_64.json | 8 +- test/code_size/test_codesize_minimal_O0.json | 8 +- test/code_size/test_codesize_minimal_O1.json | 8 +- test/code_size/test_codesize_minimal_O2.json | 8 +- test/code_size/test_codesize_minimal_O3.json | 8 +- test/code_size/test_codesize_minimal_Os.json | 8 +- .../test_codesize_minimal_Oz-ctors.json | 8 +- test/code_size/test_codesize_minimal_Oz.json | 8 +- .../test_codesize_minimal_pthreads.json | 8 +- ...t_codesize_minimal_pthreads_memgrowth.json | 8 +- .../test_codesize_minimal_wasmfs.json | 8 +- test/code_size/test_small_js_flags.json | 4 +- .../code_size/test_unoptimized_code_size.json | 16 ++-- .../test_codesize_file_preload.expected.js | 44 +++++----- .../test_codesize_minimal_O0.expected.js | 83 +------------------ tools/link.py | 2 +- 50 files changed, 204 insertions(+), 290 deletions(-) diff --git a/src/lib/libbrowser.js b/src/lib/libbrowser.js index c33bbfd152c58..9c23fe5576e8b 100644 --- a/src/lib/libbrowser.js +++ b/src/lib/libbrowser.js @@ -622,7 +622,7 @@ var LibraryBrowser = { }, // TODO: currently not callable from a pthread, but immediately calls onerror() if not on main thread. - emscripten_async_load_script__deps: ['$UTF8ToString'], + emscripten_async_load_script__deps: ['$UTF8ToString', '$runDependencies'], emscripten_async_load_script: async (url, onload, onerror) => { url = UTF8ToString(url); #if PTHREADS diff --git a/src/postamble.js b/src/postamble.js index 8275a6e891aeb..58a1420e4ed06 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -353,17 +353,18 @@ if ({{{ ENVIRONMENT_IS_MAIN_THREAD() }}}) { // In modularize mode the generated code is within a factory function so we // can use await here (since it's not top-level-await). wasmExports = await createWasm(); +run(); #else // With async instantation wasmExports is assigned asynchronously when the // instance is received. -createWasm(); +createWasm().then(() => run()); #endif #else wasmExports = createWasm(); +run(); #endif -run(); #if WASM_WORKERS || PTHREADS } diff --git a/src/preamble.js b/src/preamble.js index 007ba92645df2..8662aba6cde54 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -753,15 +753,9 @@ function getWasmImports() { #endif #if DECLARE_ASM_MODULE_EXPORTS assignWasmExports(wasmExports); -#endif -#if WASM_ASYNC_COMPILATION && !MODULARIZE - removeRunDependency('wasm-instantiate'); #endif return wasmExports; } -#if WASM_ASYNC_COMPILATION && !MODULARIZE - addRunDependency('wasm-instantiate'); -#endif // Prefer streaming instantiation if available. #if WASM_ASYNC_COMPILATION diff --git a/test/code_size/test_codesize_cxx_ctors1.json b/test/code_size/test_codesize_cxx_ctors1.json index 2e7f24e8b152d..a05dfe81fd27b 100644 --- a/test/code_size/test_codesize_cxx_ctors1.json +++ b/test/code_size/test_codesize_cxx_ctors1.json @@ -1,10 +1,10 @@ { - "a.out.js": 19754, - "a.out.js.gz": 8162, + "a.out.js": 19624, + "a.out.js.gz": 8094, "a.out.nodebug.wasm": 129508, "a.out.nodebug.wasm.gz": 49240, - "total": 149262, - "total_gz": 57402, + "total": 149132, + "total_gz": 57334, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/code_size/test_codesize_cxx_ctors2.json b/test/code_size/test_codesize_cxx_ctors2.json index f10b06668dc88..6a7c8da0c73dc 100644 --- a/test/code_size/test_codesize_cxx_ctors2.json +++ b/test/code_size/test_codesize_cxx_ctors2.json @@ -1,10 +1,10 @@ { - "a.out.js": 19732, - "a.out.js.gz": 8148, + "a.out.js": 19602, + "a.out.js.gz": 8081, "a.out.nodebug.wasm": 128935, "a.out.nodebug.wasm.gz": 48881, - "total": 148667, - "total_gz": 57029, + "total": 148537, + "total_gz": 56962, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/code_size/test_codesize_cxx_except.json b/test/code_size/test_codesize_cxx_except.json index 9b1f1fa7fbe4f..ea65e49f4d919 100644 --- a/test/code_size/test_codesize_cxx_except.json +++ b/test/code_size/test_codesize_cxx_except.json @@ -1,10 +1,10 @@ { - "a.out.js": 23415, - "a.out.js.gz": 9145, + "a.out.js": 23283, + "a.out.js.gz": 9075, "a.out.nodebug.wasm": 171270, "a.out.nodebug.wasm.gz": 57331, - "total": 194685, - "total_gz": 66476, + "total": 194553, + "total_gz": 66406, "sent": [ "__cxa_begin_catch", "__cxa_end_catch", diff --git a/test/code_size/test_codesize_cxx_except_wasm.json b/test/code_size/test_codesize_cxx_except_wasm.json index db36dd5efb67e..008d829ebca36 100644 --- a/test/code_size/test_codesize_cxx_except_wasm.json +++ b/test/code_size/test_codesize_cxx_except_wasm.json @@ -1,10 +1,10 @@ { - "a.out.js": 19643, - "a.out.js.gz": 8112, + "a.out.js": 19513, + "a.out.js.gz": 8046, "a.out.nodebug.wasm": 144629, "a.out.nodebug.wasm.gz": 54892, - "total": 164272, - "total_gz": 63004, + "total": 164142, + "total_gz": 62938, "sent": [ "_abort_js", "_tzset_js", diff --git a/test/code_size/test_codesize_cxx_except_wasm_legacy.json b/test/code_size/test_codesize_cxx_except_wasm_legacy.json index 9b95d6a2dc8e4..77e8cae98101a 100644 --- a/test/code_size/test_codesize_cxx_except_wasm_legacy.json +++ b/test/code_size/test_codesize_cxx_except_wasm_legacy.json @@ -1,10 +1,10 @@ { - "a.out.js": 19643, - "a.out.js.gz": 8112, + "a.out.js": 19513, + "a.out.js.gz": 8046, "a.out.nodebug.wasm": 142218, "a.out.nodebug.wasm.gz": 54353, - "total": 161861, - "total_gz": 62465, + "total": 161731, + "total_gz": 62399, "sent": [ "_abort_js", "_tzset_js", diff --git a/test/code_size/test_codesize_cxx_lto.json b/test/code_size/test_codesize_cxx_lto.json index 516c0c3c1e2b7..a8bc3a88b0089 100644 --- a/test/code_size/test_codesize_cxx_lto.json +++ b/test/code_size/test_codesize_cxx_lto.json @@ -1,10 +1,10 @@ { - "a.out.js": 19082, - "a.out.js.gz": 7841, + "a.out.js": 18952, + "a.out.js.gz": 7772, "a.out.nodebug.wasm": 106464, "a.out.nodebug.wasm.gz": 42600, - "total": 125546, - "total_gz": 50441, + "total": 125416, + "total_gz": 50372, "sent": [ "a (emscripten_resize_heap)", "b (_setitimer_js)", diff --git a/test/code_size/test_codesize_cxx_mangle.json b/test/code_size/test_codesize_cxx_mangle.json index ac2760145ff7f..9c99b1322ef72 100644 --- a/test/code_size/test_codesize_cxx_mangle.json +++ b/test/code_size/test_codesize_cxx_mangle.json @@ -1,10 +1,10 @@ { - "a.out.js": 23465, - "a.out.js.gz": 9164, + "a.out.js": 23333, + "a.out.js.gz": 9095, "a.out.nodebug.wasm": 235311, "a.out.nodebug.wasm.gz": 78929, - "total": 258776, - "total_gz": 88093, + "total": 258644, + "total_gz": 88024, "sent": [ "__cxa_begin_catch", "__cxa_end_catch", diff --git a/test/code_size/test_codesize_cxx_noexcept.json b/test/code_size/test_codesize_cxx_noexcept.json index b93e2c1c138a4..0554859b60a97 100644 --- a/test/code_size/test_codesize_cxx_noexcept.json +++ b/test/code_size/test_codesize_cxx_noexcept.json @@ -1,10 +1,10 @@ { - "a.out.js": 19754, - "a.out.js.gz": 8162, + "a.out.js": 19624, + "a.out.js.gz": 8094, "a.out.nodebug.wasm": 131925, "a.out.nodebug.wasm.gz": 50235, - "total": 151679, - "total_gz": 58397, + "total": 151549, + "total_gz": 58329, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/code_size/test_codesize_cxx_wasmfs.json b/test/code_size/test_codesize_cxx_wasmfs.json index 4ac7e16621441..15edd300df32b 100644 --- a/test/code_size/test_codesize_cxx_wasmfs.json +++ b/test/code_size/test_codesize_cxx_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 7143, - "a.out.js.gz": 3338, + "a.out.js": 7015, + "a.out.js.gz": 3268, "a.out.nodebug.wasm": 169796, "a.out.nodebug.wasm.gz": 63083, - "total": 176939, - "total_gz": 66421, + "total": 176811, + "total_gz": 66351, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/code_size/test_codesize_file_preload.json b/test/code_size/test_codesize_file_preload.json index a7ad8a13b7305..287fbb5eb5331 100644 --- a/test/code_size/test_codesize_file_preload.json +++ b/test/code_size/test_codesize_file_preload.json @@ -1,10 +1,10 @@ { - "a.out.js": 22684, - "a.out.js.gz": 9375, + "a.out.js": 22667, + "a.out.js.gz": 9362, "a.out.nodebug.wasm": 1681, "a.out.nodebug.wasm.gz": 960, - "total": 24365, - "total_gz": 10335, + "total": 24348, + "total_gz": 10322, "sent": [ "a (fd_write)" ], diff --git a/test/code_size/test_codesize_files_js_fs.json b/test/code_size/test_codesize_files_js_fs.json index 2938b9c5dddf7..2fe934bf80dbf 100644 --- a/test/code_size/test_codesize_files_js_fs.json +++ b/test/code_size/test_codesize_files_js_fs.json @@ -1,10 +1,10 @@ { - "a.out.js": 18357, - "a.out.js.gz": 7470, + "a.out.js": 18226, + "a.out.js.gz": 7406, "a.out.nodebug.wasm": 381, "a.out.nodebug.wasm.gz": 260, - "total": 18738, - "total_gz": 7730, + "total": 18607, + "total_gz": 7666, "sent": [ "a (fd_write)", "b (fd_read)", diff --git a/test/code_size/test_codesize_files_wasmfs.json b/test/code_size/test_codesize_files_wasmfs.json index adafe65b0caad..6764c2e2c39e9 100644 --- a/test/code_size/test_codesize_files_wasmfs.json +++ b/test/code_size/test_codesize_files_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 5549, - "a.out.js.gz": 2591, + "a.out.js": 5426, + "a.out.js.gz": 2527, "a.out.nodebug.wasm": 50232, "a.out.nodebug.wasm.gz": 18078, - "total": 55781, - "total_gz": 20669, + "total": 55658, + "total_gz": 20605, "sent": [ "a (emscripten_date_now)", "b (emscripten_err)", diff --git a/test/code_size/test_codesize_hello_O0.json b/test/code_size/test_codesize_hello_O0.json index 3cdfae395e9ea..acdf55179c11e 100644 --- a/test/code_size/test_codesize_hello_O0.json +++ b/test/code_size/test_codesize_hello_O0.json @@ -1,10 +1,10 @@ { - "a.out.js": 22496, - "a.out.js.gz": 8322, + "a.out.js": 21479, + "a.out.js.gz": 7989, "a.out.nodebug.wasm": 15127, "a.out.nodebug.wasm.gz": 7448, - "total": 37623, - "total_gz": 15770, + "total": 36606, + "total_gz": 15437, "sent": [ "fd_write" ], diff --git a/test/code_size/test_codesize_hello_O1.json b/test/code_size/test_codesize_hello_O1.json index 9b5826c312acc..2aadf55036580 100644 --- a/test/code_size/test_codesize_hello_O1.json +++ b/test/code_size/test_codesize_hello_O1.json @@ -1,10 +1,10 @@ { - "a.out.js": 6411, - "a.out.js.gz": 2472, + "a.out.js": 6197, + "a.out.js.gz": 2392, "a.out.nodebug.wasm": 2675, "a.out.nodebug.wasm.gz": 1491, - "total": 9086, - "total_gz": 3963, + "total": 8872, + "total_gz": 3883, "sent": [ "fd_write" ], diff --git a/test/code_size/test_codesize_hello_O2.json b/test/code_size/test_codesize_hello_O2.json index a3031a969bac1..c5257e2eeeebe 100644 --- a/test/code_size/test_codesize_hello_O2.json +++ b/test/code_size/test_codesize_hello_O2.json @@ -1,10 +1,10 @@ { - "a.out.js": 4369, - "a.out.js.gz": 2140, + "a.out.js": 4245, + "a.out.js.gz": 2071, "a.out.nodebug.wasm": 1927, "a.out.nodebug.wasm.gz": 1138, - "total": 6296, - "total_gz": 3278, + "total": 6172, + "total_gz": 3209, "sent": [ "fd_write" ], diff --git a/test/code_size/test_codesize_hello_O3.json b/test/code_size/test_codesize_hello_O3.json index 118da5155540d..3746a7ba1cca7 100644 --- a/test/code_size/test_codesize_hello_O3.json +++ b/test/code_size/test_codesize_hello_O3.json @@ -1,10 +1,10 @@ { - "a.out.js": 4311, - "a.out.js.gz": 2097, + "a.out.js": 4186, + "a.out.js.gz": 2029, "a.out.nodebug.wasm": 1681, "a.out.nodebug.wasm.gz": 960, - "total": 5992, - "total_gz": 3057, + "total": 5867, + "total_gz": 2989, "sent": [ "a (fd_write)" ], diff --git a/test/code_size/test_codesize_hello_Os.json b/test/code_size/test_codesize_hello_Os.json index a8941acb2fc02..a572512f3abcc 100644 --- a/test/code_size/test_codesize_hello_Os.json +++ b/test/code_size/test_codesize_hello_Os.json @@ -1,10 +1,10 @@ { - "a.out.js": 4311, - "a.out.js.gz": 2097, + "a.out.js": 4186, + "a.out.js.gz": 2029, "a.out.nodebug.wasm": 1671, "a.out.nodebug.wasm.gz": 964, - "total": 5982, - "total_gz": 3061, + "total": 5857, + "total_gz": 2993, "sent": [ "a (fd_write)" ], diff --git a/test/code_size/test_codesize_hello_Oz.json b/test/code_size/test_codesize_hello_Oz.json index 2acb815b8af13..97e1d64d3b429 100644 --- a/test/code_size/test_codesize_hello_Oz.json +++ b/test/code_size/test_codesize_hello_Oz.json @@ -1,10 +1,10 @@ { - "a.out.js": 3931, - "a.out.js.gz": 1902, + "a.out.js": 3810, + "a.out.js.gz": 1835, "a.out.nodebug.wasm": 1205, "a.out.nodebug.wasm.gz": 740, - "total": 5136, - "total_gz": 2642, + "total": 5015, + "total_gz": 2575, "sent": [ "a (fd_write)" ], diff --git a/test/code_size/test_codesize_hello_dylink.json b/test/code_size/test_codesize_hello_dylink.json index b61ce9c814299..351d05b98a161 100644 --- a/test/code_size/test_codesize_hello_dylink.json +++ b/test/code_size/test_codesize_hello_dylink.json @@ -1,10 +1,10 @@ { - "a.out.js": 26976, - "a.out.js.gz": 11458, + "a.out.js": 26943, + "a.out.js.gz": 11435, "a.out.nodebug.wasm": 18561, "a.out.nodebug.wasm.gz": 9167, - "total": 45537, - "total_gz": 20625, + "total": 45504, + "total_gz": 20602, "sent": [ "__heap_base", "__indirect_function_table", diff --git a/test/code_size/test_codesize_hello_export_nothing.json b/test/code_size/test_codesize_hello_export_nothing.json index 2d6542d43fb67..f3cedfee23c6e 100644 --- a/test/code_size/test_codesize_hello_export_nothing.json +++ b/test/code_size/test_codesize_hello_export_nothing.json @@ -1,10 +1,10 @@ { - "a.out.js": 3209, - "a.out.js.gz": 1486, + "a.out.js": 3088, + "a.out.js.gz": 1419, "a.out.nodebug.wasm": 43, "a.out.nodebug.wasm.gz": 59, - "total": 3252, - "total_gz": 1545, + "total": 3131, + "total_gz": 1478, "sent": [], "imports": [], "exports": [ diff --git a/test/code_size/test_codesize_hello_single_file.json b/test/code_size/test_codesize_hello_single_file.json index fd201b2a122f4..d405f327f7de5 100644 --- a/test/code_size/test_codesize_hello_single_file.json +++ b/test/code_size/test_codesize_hello_single_file.json @@ -1,6 +1,6 @@ { - "a.out.js": 6547, - "a.out.js.gz": 3586, + "a.out.js": 6421, + "a.out.js.gz": 3518, "sent": [ "a (fd_write)" ] diff --git a/test/code_size/test_codesize_hello_wasmfs.json b/test/code_size/test_codesize_hello_wasmfs.json index 118da5155540d..3746a7ba1cca7 100644 --- a/test/code_size/test_codesize_hello_wasmfs.json +++ b/test/code_size/test_codesize_hello_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 4311, - "a.out.js.gz": 2097, + "a.out.js": 4186, + "a.out.js.gz": 2029, "a.out.nodebug.wasm": 1681, "a.out.nodebug.wasm.gz": 960, - "total": 5992, - "total_gz": 3057, + "total": 5867, + "total_gz": 2989, "sent": [ "a (fd_write)" ], diff --git a/test/code_size/test_codesize_libcxxabi_message_O3.json b/test/code_size/test_codesize_libcxxabi_message_O3.json index 3311ada5ce962..c1a6d0c7dde25 100644 --- a/test/code_size/test_codesize_libcxxabi_message_O3.json +++ b/test/code_size/test_codesize_libcxxabi_message_O3.json @@ -1,10 +1,10 @@ { - "a.out.js": 3558, - "a.out.js.gz": 1673, + "a.out.js": 3437, + "a.out.js.gz": 1604, "a.out.nodebug.wasm": 89, "a.out.nodebug.wasm.gz": 98, - "total": 3647, - "total_gz": 1771, + "total": 3526, + "total_gz": 1702, "sent": [], "imports": [], "exports": [ diff --git a/test/code_size/test_codesize_libcxxabi_message_O3_standalone.json b/test/code_size/test_codesize_libcxxabi_message_O3_standalone.json index 524dbaf4d234d..4aeaa8c46a349 100644 --- a/test/code_size/test_codesize_libcxxabi_message_O3_standalone.json +++ b/test/code_size/test_codesize_libcxxabi_message_O3_standalone.json @@ -1,10 +1,10 @@ { - "a.out.js": 3605, - "a.out.js.gz": 1708, + "a.out.js": 3484, + "a.out.js.gz": 1638, "a.out.nodebug.wasm": 132, "a.out.nodebug.wasm.gz": 140, - "total": 3737, - "total_gz": 1848, + "total": 3616, + "total_gz": 1778, "sent": [ "proc_exit" ], diff --git a/test/code_size/test_codesize_mem_O3.json b/test/code_size/test_codesize_mem_O3.json index 207738b10d290..f24d44a55e135 100644 --- a/test/code_size/test_codesize_mem_O3.json +++ b/test/code_size/test_codesize_mem_O3.json @@ -1,10 +1,10 @@ { - "a.out.js": 4399, - "a.out.js.gz": 2112, + "a.out.js": 4279, + "a.out.js.gz": 2052, "a.out.nodebug.wasm": 5262, "a.out.nodebug.wasm.gz": 2402, - "total": 9661, - "total_gz": 4514, + "total": 9541, + "total_gz": 4454, "sent": [ "a (emscripten_resize_heap)" ], diff --git a/test/code_size/test_codesize_mem_O3_grow.json b/test/code_size/test_codesize_mem_O3_grow.json index 3c814a4cf93bf..17ee9288da070 100644 --- a/test/code_size/test_codesize_mem_O3_grow.json +++ b/test/code_size/test_codesize_mem_O3_grow.json @@ -1,10 +1,10 @@ { - "a.out.js": 4684, - "a.out.js.gz": 2264, + "a.out.js": 4565, + "a.out.js.gz": 2203, "a.out.nodebug.wasm": 5263, "a.out.nodebug.wasm.gz": 2402, - "total": 9947, - "total_gz": 4666, + "total": 9828, + "total_gz": 4605, "sent": [ "a (emscripten_resize_heap)" ], diff --git a/test/code_size/test_codesize_mem_O3_grow_standalone.json b/test/code_size/test_codesize_mem_O3_grow_standalone.json index 1f0cd89c0c8bf..25f54bc71cc18 100644 --- a/test/code_size/test_codesize_mem_O3_grow_standalone.json +++ b/test/code_size/test_codesize_mem_O3_grow_standalone.json @@ -1,10 +1,10 @@ { - "a.out.js": 4125, - "a.out.js.gz": 1977, + "a.out.js": 4010, + "a.out.js.gz": 1910, "a.out.nodebug.wasm": 5549, "a.out.nodebug.wasm.gz": 2583, - "total": 9674, - "total_gz": 4560, + "total": 9559, + "total_gz": 4493, "sent": [ "args_get", "args_sizes_get", diff --git a/test/code_size/test_codesize_mem_O3_standalone.json b/test/code_size/test_codesize_mem_O3_standalone.json index 711c31806e51b..453e85c0cffeb 100644 --- a/test/code_size/test_codesize_mem_O3_standalone.json +++ b/test/code_size/test_codesize_mem_O3_standalone.json @@ -1,10 +1,10 @@ { - "a.out.js": 4058, - "a.out.js.gz": 1941, + "a.out.js": 3943, + "a.out.js.gz": 1878, "a.out.nodebug.wasm": 5474, "a.out.nodebug.wasm.gz": 2524, - "total": 9532, - "total_gz": 4465, + "total": 9417, + "total_gz": 4402, "sent": [ "args_get", "args_sizes_get", diff --git a/test/code_size/test_codesize_mem_O3_standalone_lib.json b/test/code_size/test_codesize_mem_O3_standalone_lib.json index 0d4329085c732..36acbd195b957 100644 --- a/test/code_size/test_codesize_mem_O3_standalone_lib.json +++ b/test/code_size/test_codesize_mem_O3_standalone_lib.json @@ -1,10 +1,10 @@ { - "a.out.js": 3602, - "a.out.js.gz": 1699, + "a.out.js": 3482, + "a.out.js.gz": 1630, "a.out.nodebug.wasm": 5241, "a.out.nodebug.wasm.gz": 2332, - "total": 8843, - "total_gz": 4031, + "total": 8723, + "total_gz": 3962, "sent": [], "imports": [], "exports": [ diff --git a/test/code_size/test_codesize_mem_O3_standalone_narg.json b/test/code_size/test_codesize_mem_O3_standalone_narg.json index 853476c28f001..ab41bb832d430 100644 --- a/test/code_size/test_codesize_mem_O3_standalone_narg.json +++ b/test/code_size/test_codesize_mem_O3_standalone_narg.json @@ -1,10 +1,10 @@ { - "a.out.js": 3605, - "a.out.js.gz": 1708, + "a.out.js": 3484, + "a.out.js.gz": 1638, "a.out.nodebug.wasm": 5267, "a.out.nodebug.wasm.gz": 2364, - "total": 8872, - "total_gz": 4072, + "total": 8751, + "total_gz": 4002, "sent": [ "proc_exit" ], diff --git a/test/code_size/test_codesize_mem_O3_standalone_narg_flto.json b/test/code_size/test_codesize_mem_O3_standalone_narg_flto.json index 3cff4b2661760..342e8583fb4d8 100644 --- a/test/code_size/test_codesize_mem_O3_standalone_narg_flto.json +++ b/test/code_size/test_codesize_mem_O3_standalone_narg_flto.json @@ -1,10 +1,10 @@ { - "a.out.js": 3605, - "a.out.js.gz": 1708, + "a.out.js": 3484, + "a.out.js.gz": 1638, "a.out.nodebug.wasm": 4080, "a.out.nodebug.wasm.gz": 2001, - "total": 7685, - "total_gz": 3709, + "total": 7564, + "total_gz": 3639, "sent": [ "proc_exit" ], diff --git a/test/code_size/test_codesize_minimal_64.json b/test/code_size/test_codesize_minimal_64.json index 85e21357f6010..84741c19a71f5 100644 --- a/test/code_size/test_codesize_minimal_64.json +++ b/test/code_size/test_codesize_minimal_64.json @@ -1,10 +1,10 @@ { - "a.out.js": 2630, - "a.out.js.gz": 1253, + "a.out.js": 2558, + "a.out.js.gz": 1207, "a.out.nodebug.wasm": 62, "a.out.nodebug.wasm.gz": 76, - "total": 2692, - "total_gz": 1329, + "total": 2620, + "total_gz": 1283, "sent": [], "imports": [], "exports": [ diff --git a/test/code_size/test_codesize_minimal_O0.json b/test/code_size/test_codesize_minimal_O0.json index 31c8077ad2f0f..dbb0fd97fd63c 100644 --- a/test/code_size/test_codesize_minimal_O0.json +++ b/test/code_size/test_codesize_minimal_O0.json @@ -1,10 +1,10 @@ { - "a.out.js": 17757, - "a.out.js.gz": 6623, + "a.out.js": 16934, + "a.out.js.gz": 6341, "a.out.nodebug.wasm": 1136, "a.out.nodebug.wasm.gz": 659, - "total": 18893, - "total_gz": 7282, + "total": 18070, + "total_gz": 7000, "sent": [], "imports": [], "exports": [ diff --git a/test/code_size/test_codesize_minimal_O1.json b/test/code_size/test_codesize_minimal_O1.json index dbbfba891c2f3..69fca7401c78d 100644 --- a/test/code_size/test_codesize_minimal_O1.json +++ b/test/code_size/test_codesize_minimal_O1.json @@ -1,10 +1,10 @@ { - "a.out.js": 3096, - "a.out.js.gz": 1312, + "a.out.js": 2978, + "a.out.js.gz": 1255, "a.out.nodebug.wasm": 449, "a.out.nodebug.wasm.gz": 337, - "total": 3545, - "total_gz": 1649, + "total": 3427, + "total_gz": 1592, "sent": [], "imports": [], "exports": [ diff --git a/test/code_size/test_codesize_minimal_O2.json b/test/code_size/test_codesize_minimal_O2.json index 29e30eecc40f9..890d9a8c4c958 100644 --- a/test/code_size/test_codesize_minimal_O2.json +++ b/test/code_size/test_codesize_minimal_O2.json @@ -1,10 +1,10 @@ { - "a.out.js": 2377, - "a.out.js.gz": 1183, + "a.out.js": 2301, + "a.out.js.gz": 1134, "a.out.nodebug.wasm": 280, "a.out.nodebug.wasm.gz": 226, - "total": 2657, - "total_gz": 1409, + "total": 2581, + "total_gz": 1360, "sent": [], "imports": [], "exports": [ diff --git a/test/code_size/test_codesize_minimal_O3.json b/test/code_size/test_codesize_minimal_O3.json index c3d0ce721c3f4..b5143be28d141 100644 --- a/test/code_size/test_codesize_minimal_O3.json +++ b/test/code_size/test_codesize_minimal_O3.json @@ -1,10 +1,10 @@ { - "a.out.js": 2327, - "a.out.js.gz": 1149, + "a.out.js": 2251, + "a.out.js.gz": 1100, "a.out.nodebug.wasm": 62, "a.out.nodebug.wasm.gz": 76, - "total": 2389, - "total_gz": 1225, + "total": 2313, + "total_gz": 1176, "sent": [], "imports": [], "exports": [ diff --git a/test/code_size/test_codesize_minimal_Os.json b/test/code_size/test_codesize_minimal_Os.json index c3d0ce721c3f4..b5143be28d141 100644 --- a/test/code_size/test_codesize_minimal_Os.json +++ b/test/code_size/test_codesize_minimal_Os.json @@ -1,10 +1,10 @@ { - "a.out.js": 2327, - "a.out.js.gz": 1149, + "a.out.js": 2251, + "a.out.js.gz": 1100, "a.out.nodebug.wasm": 62, "a.out.nodebug.wasm.gz": 76, - "total": 2389, - "total_gz": 1225, + "total": 2313, + "total_gz": 1176, "sent": [], "imports": [], "exports": [ diff --git a/test/code_size/test_codesize_minimal_Oz-ctors.json b/test/code_size/test_codesize_minimal_Oz-ctors.json index dd81b49f65a99..a9578b42d27b9 100644 --- a/test/code_size/test_codesize_minimal_Oz-ctors.json +++ b/test/code_size/test_codesize_minimal_Oz-ctors.json @@ -1,10 +1,10 @@ { - "a.out.js": 2306, - "a.out.js.gz": 1133, + "a.out.js": 2232, + "a.out.js.gz": 1086, "a.out.nodebug.wasm": 51, "a.out.nodebug.wasm.gz": 68, - "total": 2357, - "total_gz": 1201, + "total": 2283, + "total_gz": 1154, "sent": [], "imports": [], "exports": [ diff --git a/test/code_size/test_codesize_minimal_Oz.json b/test/code_size/test_codesize_minimal_Oz.json index c3d0ce721c3f4..b5143be28d141 100644 --- a/test/code_size/test_codesize_minimal_Oz.json +++ b/test/code_size/test_codesize_minimal_Oz.json @@ -1,10 +1,10 @@ { - "a.out.js": 2327, - "a.out.js.gz": 1149, + "a.out.js": 2251, + "a.out.js.gz": 1100, "a.out.nodebug.wasm": 62, "a.out.nodebug.wasm.gz": 76, - "total": 2389, - "total_gz": 1225, + "total": 2313, + "total_gz": 1176, "sent": [], "imports": [], "exports": [ diff --git a/test/code_size/test_codesize_minimal_pthreads.json b/test/code_size/test_codesize_minimal_pthreads.json index adca3c803f593..8d7fd5f438625 100644 --- a/test/code_size/test_codesize_minimal_pthreads.json +++ b/test/code_size/test_codesize_minimal_pthreads.json @@ -1,10 +1,10 @@ { - "a.out.js": 7659, - "a.out.js.gz": 3776, + "a.out.js": 7594, + "a.out.js.gz": 3728, "a.out.nodebug.wasm": 19588, "a.out.nodebug.wasm.gz": 9025, - "total": 27247, - "total_gz": 12801, + "total": 27182, + "total_gz": 12753, "sent": [ "a (memory)", "b (emscripten_get_now)", diff --git a/test/code_size/test_codesize_minimal_pthreads_memgrowth.json b/test/code_size/test_codesize_minimal_pthreads_memgrowth.json index c60838f5e66fc..97a1e3ec31c8a 100644 --- a/test/code_size/test_codesize_minimal_pthreads_memgrowth.json +++ b/test/code_size/test_codesize_minimal_pthreads_memgrowth.json @@ -1,10 +1,10 @@ { - "a.out.js": 8086, - "a.out.js.gz": 3977, + "a.out.js": 8021, + "a.out.js.gz": 3929, "a.out.nodebug.wasm": 19589, "a.out.nodebug.wasm.gz": 9025, - "total": 27675, - "total_gz": 13002, + "total": 27610, + "total_gz": 12954, "sent": [ "a (memory)", "b (emscripten_get_now)", diff --git a/test/code_size/test_codesize_minimal_wasmfs.json b/test/code_size/test_codesize_minimal_wasmfs.json index c3d0ce721c3f4..b5143be28d141 100644 --- a/test/code_size/test_codesize_minimal_wasmfs.json +++ b/test/code_size/test_codesize_minimal_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 2327, - "a.out.js.gz": 1149, + "a.out.js": 2251, + "a.out.js.gz": 1100, "a.out.nodebug.wasm": 62, "a.out.nodebug.wasm.gz": 76, - "total": 2389, - "total_gz": 1225, + "total": 2313, + "total_gz": 1176, "sent": [], "imports": [], "exports": [ diff --git a/test/code_size/test_small_js_flags.json b/test/code_size/test_small_js_flags.json index e5825250e8677..b822ddeedd09c 100644 --- a/test/code_size/test_small_js_flags.json +++ b/test/code_size/test_small_js_flags.json @@ -1,4 +1,4 @@ { - "a.out.js": 2763, - "a.out.js.gz": 1494 + "a.out.js": 2677, + "a.out.js.gz": 1456 } diff --git a/test/code_size/test_unoptimized_code_size.json b/test/code_size/test_unoptimized_code_size.json index 9e58f90850b39..3f1ba62722e46 100644 --- a/test/code_size/test_unoptimized_code_size.json +++ b/test/code_size/test_unoptimized_code_size.json @@ -1,16 +1,16 @@ { - "hello_world.js": 53881, - "hello_world.js.gz": 17016, + "hello_world.js": 51572, + "hello_world.js.gz": 16461, "hello_world.wasm": 15127, "hello_world.wasm.gz": 7448, - "no_asserts.js": 26352, - "no_asserts.js.gz": 8789, + "no_asserts.js": 25482, + "no_asserts.js.gz": 8606, "no_asserts.wasm": 12227, "no_asserts.wasm.gz": 6008, - "strict.js": 51919, - "strict.js.gz": 16352, + "strict.js": 49734, + "strict.js.gz": 15824, "strict.wasm": 15127, "strict.wasm.gz": 7445, - "total": 174633, - "total_gz": 63058 + "total": 169269, + "total_gz": 61792 } diff --git a/test/other/codesize/test_codesize_file_preload.expected.js b/test/other/codesize/test_codesize_file_preload.expected.js index f8ec8a8646ec5..35516ac848e93 100644 --- a/test/other/codesize/test_codesize_file_preload.expected.js +++ b/test/other/codesize/test_codesize_file_preload.expected.js @@ -461,10 +461,8 @@ async function createWasm() { wasmMemory = wasmExports["b"]; updateMemoryViews(); assignWasmExports(wasmExports); - removeRunDependency("wasm-instantiate"); return wasmExports; } - addRunDependency("wasm-instantiate"); // Prefer streaming instantiation if available. function receiveInstantiationResult(result) { // 'result' is a ResultObject object which has both the module and instance. @@ -501,25 +499,6 @@ var onPreRuns = []; var addOnPreRun = cb => onPreRuns.push(cb); -var runDependencies = 0; - -var dependenciesFulfilled = null; - -var removeRunDependency = id => { - runDependencies--; - if (runDependencies == 0) { - if (dependenciesFulfilled) { - var callback = dependenciesFulfilled; - dependenciesFulfilled = null; - callback(); - } - } -}; - -var addRunDependency = id => { - runDependencies++; -}; - /** @param {number=} offset */ var doWritev = (stream, iov, iovcnt, offset) => { var ret = 0; for (var i = 0; i < iovcnt; i++) { @@ -1325,6 +1304,25 @@ var FS_createDataFile = (...args) => FS.createDataFile(...args); var getUniqueRunDependency = id => id; +var runDependencies = 0; + +var dependenciesFulfilled = null; + +var removeRunDependency = id => { + runDependencies--; + if (runDependencies == 0) { + if (dependenciesFulfilled) { + var callback = dependenciesFulfilled; + dependenciesFulfilled = null; + callback(); + } + } +}; + +var addRunDependency = id => { + runDependencies++; +}; + var preloadPlugins = []; var FS_handledByPreloadPlugin = async (byteArray, fullname) => { @@ -3210,6 +3208,4 @@ var wasmExports; // With async instantation wasmExports is assigned asynchronously when the // instance is received. -createWasm(); - -run(); +createWasm().then(() => run()); diff --git a/test/other/codesize/test_codesize_minimal_O0.expected.js b/test/other/codesize/test_codesize_minimal_O0.expected.js index da2b6ec3422f0..a6d91edc96714 100644 --- a/test/other/codesize/test_codesize_minimal_O0.expected.js +++ b/test/other/codesize/test_codesize_minimal_O0.expected.js @@ -656,10 +656,8 @@ async function createWasm() { updateMemoryViews(); assignWasmExports(wasmExports); - removeRunDependency('wasm-instantiate'); return wasmExports; } - addRunDependency('wasm-instantiate'); // Prefer streaming instantiation if available. // Async compilation can be confusing when an error on the page overwrites Module @@ -697,67 +695,6 @@ async function createWasm() { } } - var runDependencies = 0; - - - var dependenciesFulfilled = null; - - var runDependencyTracking = { - }; - - var runDependencyWatcher = null; - var removeRunDependency = (id) => { - runDependencies--; - - assert(id, 'removeRunDependency requires an ID'); - assert(runDependencyTracking[id]); - delete runDependencyTracking[id]; - if (runDependencies == 0) { - if (runDependencyWatcher !== null) { - clearInterval(runDependencyWatcher); - runDependencyWatcher = null; - } - if (dependenciesFulfilled) { - var callback = dependenciesFulfilled; - dependenciesFulfilled = null; - callback(); // can add another dependenciesFulfilled - } - } - }; - - - var addRunDependency = (id) => { - runDependencies++; - - assert(id, 'addRunDependency requires an ID') - assert(!runDependencyTracking[id]); - runDependencyTracking[id] = 1; - if (runDependencyWatcher === null && typeof setInterval != 'undefined') { - // Check for missing dependencies every few seconds - runDependencyWatcher = setInterval(() => { - if (ABORT) { - clearInterval(runDependencyWatcher); - runDependencyWatcher = null; - return; - } - var shown = false; - for (var dep in runDependencyTracking) { - if (!shown) { - shown = true; - err('still waiting on run dependencies:'); - } - err(`dependency: ${dep}`); - } - if (shown) { - err('(end of list)'); - } - }, 10000); - // Prevent this timer from keeping the runtime alive if nothing - // else is. - runDependencyWatcher.unref?.() - } - }; - var callRuntimeCallbacks = (callbacks) => { while (callbacks.length > 0) { // Pass the module as the first argument. @@ -792,7 +729,6 @@ async function createWasm() { return '0x' + ptr.toString(16).padStart(8, '0'); }; - /** * @param {number} ptr @@ -912,6 +848,8 @@ Module['FS_createPreloadedFile'] = FS.createPreloadedFile; 'HandleAllocator', 'getNativeTypeSize', 'getUniqueRunDependency', + 'addRunDependency', + 'removeRunDependency', 'addOnPreRun', 'addOnInit', 'addOnPostCtor', @@ -1060,8 +998,6 @@ missingLibrarySymbols.forEach(missingLibrarySymbol) 'readEmAsmArgsArray', 'wasmTable', 'noExitRuntime', - 'addRunDependency', - 'removeRunDependency', 'freeTableIndexes', 'functionsInTableMap', 'setValue', @@ -1323,21 +1259,10 @@ function stackCheckInit() { function run() { - if (runDependencies > 0) { - dependenciesFulfilled = run; - return; - } - stackCheckInit(); preRun(); - // a preRun added a dependency, run will be called later - if (runDependencies > 0) { - dependenciesFulfilled = run; - return; - } - function doRun() { // run may have just been called through dependencies being fulfilled just in this very frame, // or while the async setStatus time below was happening @@ -1393,9 +1318,7 @@ var wasmExports; // With async instantation wasmExports is assigned asynchronously when the // instance is received. -createWasm(); - -run(); +createWasm().then(() => run()); // end include: postamble.js diff --git a/tools/link.py b/tools/link.py index 021513da8a4ce..b6e41b517239b 100644 --- a/tools/link.py +++ b/tools/link.py @@ -1134,7 +1134,7 @@ def limit_incoming_module_api(): settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$ExitStatus'] # Certain configurations require the removeRunDependency/addRunDependency system. - if settings.LOAD_SOURCE_MAP or settings.PROXY_TO_WORKER or (settings.WASM_ASYNC_COMPILATION and not settings.MODULARIZE): + if settings.LOAD_SOURCE_MAP or settings.PROXY_TO_WORKER: settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$addRunDependency', '$removeRunDependency'] if settings.ABORT_ON_WASM_EXCEPTIONS or settings.SPLIT_MODULE: