From e51fedabd001a55757b50a2ae1bd13a6893a2d6d Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 15 Oct 2025 01:53:10 +0000 Subject: [PATCH 01/17] [SPLIT_MODULE] Make getWasmImports return Proxy (NFC) When `SPLIT_MODULE` is set, this makes the `imports` object returned by `getWasmImports` itself a Proxy, which redirects property requests starting with `placeholder` to an inner `splitModuleProxyHandler` that processes the second module loading, and process all other property requests to the original `imports` object itself. This is a prepration to add multi-split loading functionality to the JS runtime. In the multi-split mode, we don't have a single seconday module `[modulename].deferred.wasm`, but instead multiple secondary modules. We plan to have multiple placeholder namespace (e.g., `placeholder_2`, `placeholder_3`, ...) that match those multiple files, and this can't be hardcoded with one `placeholder` string as we currently do, so having the `imports` object itself as a `Proxy` provides us flexibility to handle multiple placeholder namespaces and load correct modules later. --- src/preamble.js | 50 ++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/src/preamble.js b/src/preamble.js index 89f10bb379b38..3dd5ec9689184 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -487,27 +487,37 @@ async function getWasmBinary(binaryFile) { #if SPLIT_MODULE {{{ makeModuleReceiveWithVar('loadSplitModule', undefined, 'instantiateSync') }}} -var splitModuleProxyHandler = { +var wasmImportsProxyHandler = { get(target, prop, receiver) { - return (...args) => { + if (prop.startsWith('placeholder')) { + const moduleName = prop; + var splitModuleProxyHandler = { + get(target, prop, receiver) { + return (...args) => { #if ASYNCIFY == 2 - throw new Error('Placeholder function "' + prop + '" should not be called when using JSPI.'); + throw new Error('Placeholder function "' + prop + '" should not be called when using JSPI.'); #else - err(`placeholder function called: ${prop}`); - var imports = {'primary': wasmExports}; - // Replace '.wasm' suffix with '.deferred.wasm'. - var deferred = wasmBinaryFile.slice(0, -5) + '.deferred.wasm' - loadSplitModule(deferred, imports, prop); - err('instantiated deferred module, continuing'); + // TODO: Implement multi-split module loading + err(`placeholder function called: ${prop}`); + var imports = {'primary': wasmExports}; + // Replace '.wasm' suffix with '.deferred.wasm'. + var deferred = wasmBinaryFile.slice(0, -5) + '.deferred.wasm' + loadSplitModule(deferred, imports, prop); + err('instantiated deferred module, continuing'); #if RELOCATABLE - // When the table is dynamically laid out, the placeholder functions names - // are offsets from the table base. In the main module, the table base is - // always 1. - prop = 1 + parseInt(prop); + // When the table is dynamically laid out, the placeholder functions names + // are offsets from the table base. In the main module, the table base is + // always 1. + prop = 1 + parseInt(prop); #endif - return wasmTable.get({{{ toIndexType('prop') }}})(...args); + return wasmTable.get({{{ toIndexType('prop') }}})(...args); #endif + } + } + }; + return new Proxy({}, splitModuleProxyHandler); } + return target[prop]; } }; #endif @@ -633,6 +643,7 @@ async function instantiateAsync(binary, binaryFile, imports) { #endif // SOURCE_PHASE_IMPORTS #if !WASM_ESM_INTEGRATION + function getWasmImports() { #if PTHREADS || WASM_WORKERS || (IMPORTED_MEMORY && MODULARIZE == 'instance') assignWasmImports(); @@ -653,21 +664,22 @@ function getWasmImports() { #endif #endif // prepare imports - return { + var imports = { #if MINIFY_WASM_IMPORTED_MODULES 'a': wasmImports, #else // MINIFY_WASM_IMPORTED_MODULES 'env': wasmImports, '{{{ WASI_MODULE_NAME }}}': wasmImports, #endif // MINIFY_WASM_IMPORTED_MODULES -#if SPLIT_MODULE - 'placeholder': new Proxy({}, splitModuleProxyHandler), -#endif #if RELOCATABLE 'GOT.mem': new Proxy(wasmImports, GOTHandler), 'GOT.func': new Proxy(wasmImports, GOTHandler), #endif - } + }; +#if SPLIT_MODULE + imports = new Proxy(imports, wasmImportsProxyHandler); +#endif + return imports; } // Create the wasm instance. From 470fcfb52034fa0bdf29472fcc9325696710aecb Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 15 Oct 2025 05:58:07 +0000 Subject: [PATCH 02/17] Automatic rebaseline of codesize expectations. NFC This is an automatic change generated by tools/maint/rebaseline_tests.py. The following (7) test expectation files were updated by running the tests with `--rebaseline`: ``` codesize/test_codesize_cxx_wasmfs.json: 176780 => 176780 [+0 bytes / +0.00%] test/codesize/test_codesize_file_preload.expected.js updated codesize/test_codesize_files_wasmfs.json: 55683 => 55683 [+0 bytes / +0.00%] codesize/test_codesize_hello_O0.json: 39197 => 39189 [-8 bytes / -0.02%] codesize/test_codesize_hello_dylink_all.json: 843553 => 843559 [+6 bytes / +0.00%] test/codesize/test_codesize_minimal_O0.expected.js updated codesize/test_unoptimized_code_size.json: 180236 => 180290 [+54 bytes / +0.03%] Average change: +0.00% (-0.02% - +0.03%) ``` --- test/codesize/test_codesize_cxx_wasmfs.json | 4 +-- .../test_codesize_file_preload.expected.js | 3 +- test/codesize/test_codesize_files_wasmfs.json | 4 +-- test/codesize/test_codesize_hello_O0.json | 8 +++--- .../test_codesize_hello_dylink_all.json | 4 +-- .../test_codesize_minimal_O0.expected.js | 5 ++-- test/codesize/test_unoptimized_code_size.json | 28 +++++++++---------- 7 files changed, 29 insertions(+), 27 deletions(-) diff --git a/test/codesize/test_codesize_cxx_wasmfs.json b/test/codesize/test_codesize_cxx_wasmfs.json index 3b2be1f142d31..3021f01f12876 100644 --- a/test/codesize/test_codesize_cxx_wasmfs.json +++ b/test/codesize/test_codesize_cxx_wasmfs.json @@ -2,9 +2,9 @@ "a.out.js": 7059, "a.out.js.gz": 3330, "a.out.nodebug.wasm": 169721, - "a.out.nodebug.wasm.gz": 62983, + "a.out.nodebug.wasm.gz": 62981, "total": 176780, - "total_gz": 66313, + "total_gz": 66311, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_file_preload.expected.js b/test/codesize/test_codesize_file_preload.expected.js index 6a54d91bcc8e2..c4e879be679a1 100644 --- a/test/codesize/test_codesize_file_preload.expected.js +++ b/test/codesize/test_codesize_file_preload.expected.js @@ -447,9 +447,10 @@ async function instantiateAsync(binary, binaryFile, imports) { function getWasmImports() { // prepare imports - return { + var imports = { "a": wasmImports }; + return imports; } // Create the wasm instance. diff --git a/test/codesize/test_codesize_files_wasmfs.json b/test/codesize/test_codesize_files_wasmfs.json index 5497bd2b1ee39..fb687e208a871 100644 --- a/test/codesize/test_codesize_files_wasmfs.json +++ b/test/codesize/test_codesize_files_wasmfs.json @@ -2,9 +2,9 @@ "a.out.js": 5465, "a.out.js.gz": 2576, "a.out.nodebug.wasm": 50218, - "a.out.nodebug.wasm.gz": 18082, + "a.out.nodebug.wasm.gz": 18086, "total": 55683, - "total_gz": 20658, + "total_gz": 20662, "sent": [ "a (emscripten_date_now)", "b (emscripten_err)", diff --git a/test/codesize/test_codesize_hello_O0.json b/test/codesize/test_codesize_hello_O0.json index 3586b686893df..701ff3b943459 100644 --- a/test/codesize/test_codesize_hello_O0.json +++ b/test/codesize/test_codesize_hello_O0.json @@ -1,10 +1,10 @@ { "a.out.js": 24070, "a.out.js.gz": 8666, - "a.out.nodebug.wasm": 15127, - "a.out.nodebug.wasm.gz": 7450, - "total": 39197, - "total_gz": 16116, + "a.out.nodebug.wasm": 15119, + "a.out.nodebug.wasm.gz": 7444, + "total": 39189, + "total_gz": 16110, "sent": [ "fd_write" ], diff --git a/test/codesize/test_codesize_hello_dylink_all.json b/test/codesize/test_codesize_hello_dylink_all.json index aa27e63c7d228..05ebe029c71ac 100644 --- a/test/codesize/test_codesize_hello_dylink_all.json +++ b/test/codesize/test_codesize_hello_dylink_all.json @@ -1,7 +1,7 @@ { "a.out.js": 245829, - "a.out.nodebug.wasm": 597724, - "total": 843553, + "a.out.nodebug.wasm": 597730, + "total": 843559, "sent": [ "IMG_Init", "IMG_Load", diff --git a/test/codesize/test_codesize_minimal_O0.expected.js b/test/codesize/test_codesize_minimal_O0.expected.js index cd9adf6366115..52577c13e659f 100644 --- a/test/codesize/test_codesize_minimal_O0.expected.js +++ b/test/codesize/test_codesize_minimal_O0.expected.js @@ -658,10 +658,11 @@ async function instantiateAsync(binary, binaryFile, imports) { function getWasmImports() { // prepare imports - return { + var imports = { 'env': wasmImports, 'wasi_snapshot_preview1': wasmImports, - } + }; + return imports; } // Create the wasm instance. diff --git a/test/codesize/test_unoptimized_code_size.json b/test/codesize/test_unoptimized_code_size.json index d8c830a2899cb..ae60057550c37 100644 --- a/test/codesize/test_unoptimized_code_size.json +++ b/test/codesize/test_unoptimized_code_size.json @@ -1,16 +1,16 @@ { - "hello_world.js": 56566, - "hello_world.js.gz": 17601, - "hello_world.wasm": 15127, - "hello_world.wasm.gz": 7450, - "no_asserts.js": 26608, - "no_asserts.js.gz": 8874, - "no_asserts.wasm": 12227, - "no_asserts.wasm.gz": 6010, - "strict.js": 54581, - "strict.js.gz": 16947, - "strict.wasm": 15127, - "strict.wasm.gz": 7447, - "total": 180236, - "total_gz": 64329 + "hello_world.js": 56592, + "hello_world.js.gz": 17608, + "hello_world.wasm": 15119, + "hello_world.wasm.gz": 7444, + "no_asserts.js": 26634, + "no_asserts.js.gz": 8883, + "no_asserts.wasm": 12219, + "no_asserts.wasm.gz": 6005, + "strict.js": 54607, + "strict.js.gz": 16955, + "strict.wasm": 15119, + "strict.wasm.gz": 7442, + "total": 180290, + "total_gz": 64337 } From 6a30a500744cdbae804a7ceff78c1015d8966de4 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 15 Oct 2025 06:18:06 +0000 Subject: [PATCH 03/17] Address a comment --- src/preamble.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/preamble.js b/src/preamble.js index 3dd5ec9689184..4d38d912aa456 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -488,9 +488,8 @@ async function getWasmBinary(binaryFile) { #if SPLIT_MODULE {{{ makeModuleReceiveWithVar('loadSplitModule', undefined, 'instantiateSync') }}} var wasmImportsProxyHandler = { - get(target, prop, receiver) { - if (prop.startsWith('placeholder')) { - const moduleName = prop; + get(target, namespace, receiver) { + if (namespace.startsWith('placeholder')) { var splitModuleProxyHandler = { get(target, prop, receiver) { return (...args) => { @@ -517,7 +516,7 @@ var wasmImportsProxyHandler = { }; return new Proxy({}, splitModuleProxyHandler); } - return target[prop]; + return target[namespace]; } }; #endif From 3c5e7ad2282f444704a5cee4c3b70791c1dca231 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 15 Oct 2025 06:21:03 +0000 Subject: [PATCH 04/17] namespace -> env --- src/preamble.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/preamble.js b/src/preamble.js index 4d38d912aa456..5286391de61ab 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -488,8 +488,8 @@ async function getWasmBinary(binaryFile) { #if SPLIT_MODULE {{{ makeModuleReceiveWithVar('loadSplitModule', undefined, 'instantiateSync') }}} var wasmImportsProxyHandler = { - get(target, namespace, receiver) { - if (namespace.startsWith('placeholder')) { + get(target, env, receiver) { + if (env.startsWith('placeholder')) { var splitModuleProxyHandler = { get(target, prop, receiver) { return (...args) => { @@ -516,7 +516,7 @@ var wasmImportsProxyHandler = { }; return new Proxy({}, splitModuleProxyHandler); } - return target[namespace]; + return target[env]; } }; #endif From 3ddcbd19848e05a759127d9ad4f66b3b8995a111 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 15 Oct 2025 06:55:59 +0000 Subject: [PATCH 05/17] Rename `prop` -> `base` --- src/preamble.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/preamble.js b/src/preamble.js index 5286391de61ab..328ea113ec79f 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -491,25 +491,25 @@ var wasmImportsProxyHandler = { get(target, env, receiver) { if (env.startsWith('placeholder')) { var splitModuleProxyHandler = { - get(target, prop, receiver) { + get(target, base, receiver) { return (...args) => { #if ASYNCIFY == 2 - throw new Error('Placeholder function "' + prop + '" should not be called when using JSPI.'); + throw new Error('Placeholder function "' + base + '" should not be called when using JSPI.'); #else // TODO: Implement multi-split module loading - err(`placeholder function called: ${prop}`); + err(`placeholder function called: ${base}`); var imports = {'primary': wasmExports}; // Replace '.wasm' suffix with '.deferred.wasm'. var deferred = wasmBinaryFile.slice(0, -5) + '.deferred.wasm' - loadSplitModule(deferred, imports, prop); + loadSplitModule(deferred, imports, base); err('instantiated deferred module, continuing'); #if RELOCATABLE // When the table is dynamically laid out, the placeholder functions names // are offsets from the table base. In the main module, the table base is // always 1. - prop = 1 + parseInt(prop); + base = 1 + parseInt(base); #endif - return wasmTable.get({{{ toIndexType('prop') }}})(...args); + return wasmTable.get({{{ toIndexType('base') }}})(...args); #endif } } From b2a22d437a9c383dfaecfbe9abb4a0eba689ec8c Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 15 Oct 2025 07:03:35 +0000 Subject: [PATCH 06/17] [SPLIT_MODULE] Support multi-split loading --- src/preamble.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/preamble.js b/src/preamble.js index 328ea113ec79f..f697f4bb82846 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -490,6 +490,13 @@ async function getWasmBinary(binaryFile) { var wasmImportsProxyHandler = { get(target, env, receiver) { if (env.startsWith('placeholder')) { + let secondaryFile; + if (env == 'placeholder') { + secondaryFile = wasmBinaryFile.slice(0, -5) + '.deferred.wasm'; + } else { + let moduleID = env.split('.')[1]; + secondaryFile = wasmBinaryFile.slice(0, -5) + '.' + moduleID + '.wasm'; + } var splitModuleProxyHandler = { get(target, base, receiver) { return (...args) => { @@ -500,8 +507,7 @@ var wasmImportsProxyHandler = { err(`placeholder function called: ${base}`); var imports = {'primary': wasmExports}; // Replace '.wasm' suffix with '.deferred.wasm'. - var deferred = wasmBinaryFile.slice(0, -5) + '.deferred.wasm' - loadSplitModule(deferred, imports, base); + loadSplitModule(secondaryFile, imports, base); err('instantiated deferred module, continuing'); #if RELOCATABLE // When the table is dynamically laid out, the placeholder functions names From e918916ecd5a4705c6c98bf21f694ad2b2983864 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 15 Oct 2025 21:43:19 +0000 Subject: [PATCH 07/17] wasmImportsProxyHandler -> splitImportsProxyHandler --- src/preamble.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/preamble.js b/src/preamble.js index f697f4bb82846..0ec5415ef7e80 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -487,7 +487,7 @@ async function getWasmBinary(binaryFile) { #if SPLIT_MODULE {{{ makeModuleReceiveWithVar('loadSplitModule', undefined, 'instantiateSync') }}} -var wasmImportsProxyHandler = { +var splitImportsProxyHandler = { get(target, env, receiver) { if (env.startsWith('placeholder')) { let secondaryFile; @@ -682,7 +682,7 @@ function getWasmImports() { #endif }; #if SPLIT_MODULE - imports = new Proxy(imports, wasmImportsProxyHandler); + imports = new Proxy(imports, splitImportsProxyHandler); #endif return imports; } From 6cb0c42754724b6682640750a628aba986c8b329 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 15 Oct 2025 21:44:42 +0000 Subject: [PATCH 08/17] env -> moduleName --- src/preamble.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/preamble.js b/src/preamble.js index 0ec5415ef7e80..8941daeb6af5c 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -488,13 +488,13 @@ async function getWasmBinary(binaryFile) { #if SPLIT_MODULE {{{ makeModuleReceiveWithVar('loadSplitModule', undefined, 'instantiateSync') }}} var splitImportsProxyHandler = { - get(target, env, receiver) { - if (env.startsWith('placeholder')) { + get(target, moduleName, receiver) { + if (moduleName.startsWith('placeholder')) { let secondaryFile; - if (env == 'placeholder') { + if (moduleName == 'placeholder') { secondaryFile = wasmBinaryFile.slice(0, -5) + '.deferred.wasm'; } else { - let moduleID = env.split('.')[1]; + let moduleID = moduleName.split('.')[1]; secondaryFile = wasmBinaryFile.slice(0, -5) + '.' + moduleID + '.wasm'; } var splitModuleProxyHandler = { @@ -522,7 +522,7 @@ var splitImportsProxyHandler = { }; return new Proxy({}, splitModuleProxyHandler); } - return target[env]; + return target[moduleName]; } }; #endif From 4f2f3b394450db70eec4f97945ec5edce5049bbc Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 15 Oct 2025 21:46:10 +0000 Subject: [PATCH 09/17] Wrap dbg messages within RUNTIME_DEBUG --- src/preamble.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/preamble.js b/src/preamble.js index 8941daeb6af5c..710e478c0b68a 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -504,11 +504,15 @@ var splitImportsProxyHandler = { throw new Error('Placeholder function "' + base + '" should not be called when using JSPI.'); #else // TODO: Implement multi-split module loading - err(`placeholder function called: ${base}`); +#if RUNTIME_DEBUG + dbg(`placeholder function called: ${base}`); +#endif var imports = {'primary': wasmExports}; // Replace '.wasm' suffix with '.deferred.wasm'. loadSplitModule(secondaryFile, imports, base); - err('instantiated deferred module, continuing'); +#if RUNTIME_DEBUG + dbg('instantiated deferred module, continuing'); +#endif #if RELOCATABLE // When the table is dynamically laid out, the placeholder functions names // are offsets from the table base. In the main module, the table base is From 68c330878fcc4e2049c7e5a0788b4fd2149838ef Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 15 Oct 2025 23:29:35 +0000 Subject: [PATCH 10/17] Revert "[SPLIT_MODULE] Support multi-split loading" This reverts commit b2a22d437a9c383dfaecfbe9abb4a0eba689ec8c. --- src/preamble.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/preamble.js b/src/preamble.js index 710e478c0b68a..8c97ea91ed714 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -490,13 +490,6 @@ async function getWasmBinary(binaryFile) { var splitImportsProxyHandler = { get(target, moduleName, receiver) { if (moduleName.startsWith('placeholder')) { - let secondaryFile; - if (moduleName == 'placeholder') { - secondaryFile = wasmBinaryFile.slice(0, -5) + '.deferred.wasm'; - } else { - let moduleID = moduleName.split('.')[1]; - secondaryFile = wasmBinaryFile.slice(0, -5) + '.' + moduleID + '.wasm'; - } var splitModuleProxyHandler = { get(target, base, receiver) { return (...args) => { From eaea168cee1d1c7a423b2abed387f07d7e6aab62 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 15 Oct 2025 23:36:35 +0000 Subject: [PATCH 11/17] Rename handlers --- src/preamble.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/preamble.js b/src/preamble.js index 8c97ea91ed714..3fa0fc3ed3b22 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -487,10 +487,10 @@ async function getWasmBinary(binaryFile) { #if SPLIT_MODULE {{{ makeModuleReceiveWithVar('loadSplitModule', undefined, 'instantiateSync') }}} -var splitImportsProxyHandler = { +var splitModuleProxyHandler = { get(target, moduleName, receiver) { if (moduleName.startsWith('placeholder')) { - var splitModuleProxyHandler = { + var innerHandler = { get(target, base, receiver) { return (...args) => { #if ASYNCIFY == 2 @@ -517,7 +517,7 @@ var splitImportsProxyHandler = { } } }; - return new Proxy({}, splitModuleProxyHandler); + return new Proxy({}, innerHandler); } return target[moduleName]; } @@ -679,7 +679,7 @@ function getWasmImports() { #endif }; #if SPLIT_MODULE - imports = new Proxy(imports, splitImportsProxyHandler); + imports = new Proxy(imports, splitModuleProxyHandler); #endif return imports; } From 147482f49c53252e7182fdb901a80e9196e3ed57 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 15 Oct 2025 23:38:54 +0000 Subject: [PATCH 12/17] Automatic rebaseline of codesize expectations. NFC This is an automatic change generated by tools/maint/rebaseline_tests.py. The following (5) test expectation files were updated by running the tests with `--rebaseline`: ``` codesize/test_codesize_cxx_wasmfs.json: 176780 => 176780 [+0 bytes / +0.00%] codesize/test_codesize_files_wasmfs.json: 55683 => 55683 [+0 bytes / +0.00%] codesize/test_codesize_hello_O0.json: 39189 => 39197 [+8 bytes / +0.02%] codesize/test_codesize_hello_dylink_all.json: 843559 => 843553 [-6 bytes / -0.00%] codesize/test_unoptimized_code_size.json: 180290 => 180314 [+24 bytes / +0.01%] Average change: +0.01% (-0.00% - +0.02%) ``` --- test/codesize/test_codesize_cxx_wasmfs.json | 4 ++-- test/codesize/test_codesize_files_wasmfs.json | 4 ++-- test/codesize/test_codesize_hello_O0.json | 8 ++++---- .../codesize/test_codesize_hello_dylink_all.json | 4 ++-- test/codesize/test_unoptimized_code_size.json | 16 ++++++++-------- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/test/codesize/test_codesize_cxx_wasmfs.json b/test/codesize/test_codesize_cxx_wasmfs.json index 3021f01f12876..3b2be1f142d31 100644 --- a/test/codesize/test_codesize_cxx_wasmfs.json +++ b/test/codesize/test_codesize_cxx_wasmfs.json @@ -2,9 +2,9 @@ "a.out.js": 7059, "a.out.js.gz": 3330, "a.out.nodebug.wasm": 169721, - "a.out.nodebug.wasm.gz": 62981, + "a.out.nodebug.wasm.gz": 62983, "total": 176780, - "total_gz": 66311, + "total_gz": 66313, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_files_wasmfs.json b/test/codesize/test_codesize_files_wasmfs.json index fb687e208a871..5497bd2b1ee39 100644 --- a/test/codesize/test_codesize_files_wasmfs.json +++ b/test/codesize/test_codesize_files_wasmfs.json @@ -2,9 +2,9 @@ "a.out.js": 5465, "a.out.js.gz": 2576, "a.out.nodebug.wasm": 50218, - "a.out.nodebug.wasm.gz": 18086, + "a.out.nodebug.wasm.gz": 18082, "total": 55683, - "total_gz": 20662, + "total_gz": 20658, "sent": [ "a (emscripten_date_now)", "b (emscripten_err)", diff --git a/test/codesize/test_codesize_hello_O0.json b/test/codesize/test_codesize_hello_O0.json index 701ff3b943459..3586b686893df 100644 --- a/test/codesize/test_codesize_hello_O0.json +++ b/test/codesize/test_codesize_hello_O0.json @@ -1,10 +1,10 @@ { "a.out.js": 24070, "a.out.js.gz": 8666, - "a.out.nodebug.wasm": 15119, - "a.out.nodebug.wasm.gz": 7444, - "total": 39189, - "total_gz": 16110, + "a.out.nodebug.wasm": 15127, + "a.out.nodebug.wasm.gz": 7450, + "total": 39197, + "total_gz": 16116, "sent": [ "fd_write" ], diff --git a/test/codesize/test_codesize_hello_dylink_all.json b/test/codesize/test_codesize_hello_dylink_all.json index 05ebe029c71ac..aa27e63c7d228 100644 --- a/test/codesize/test_codesize_hello_dylink_all.json +++ b/test/codesize/test_codesize_hello_dylink_all.json @@ -1,7 +1,7 @@ { "a.out.js": 245829, - "a.out.nodebug.wasm": 597730, - "total": 843559, + "a.out.nodebug.wasm": 597724, + "total": 843553, "sent": [ "IMG_Init", "IMG_Load", diff --git a/test/codesize/test_unoptimized_code_size.json b/test/codesize/test_unoptimized_code_size.json index ae60057550c37..c583e5c655fb6 100644 --- a/test/codesize/test_unoptimized_code_size.json +++ b/test/codesize/test_unoptimized_code_size.json @@ -1,16 +1,16 @@ { "hello_world.js": 56592, "hello_world.js.gz": 17608, - "hello_world.wasm": 15119, - "hello_world.wasm.gz": 7444, + "hello_world.wasm": 15127, + "hello_world.wasm.gz": 7450, "no_asserts.js": 26634, "no_asserts.js.gz": 8883, - "no_asserts.wasm": 12219, - "no_asserts.wasm.gz": 6005, + "no_asserts.wasm": 12227, + "no_asserts.wasm.gz": 6010, "strict.js": 54607, "strict.js.gz": 16955, - "strict.wasm": 15119, - "strict.wasm.gz": 7442, - "total": 180290, - "total_gz": 64337 + "strict.wasm": 15127, + "strict.wasm.gz": 7447, + "total": 180314, + "total_gz": 64353 } From 3919476bc3c5735dc68ff7dfe2565669a670e7b5 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 15 Oct 2025 23:54:27 +0000 Subject: [PATCH 13/17] Fix errors from previous revert ;( --- src/preamble.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/preamble.js b/src/preamble.js index 3fa0fc3ed3b22..4226ea800efe3 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -502,7 +502,8 @@ var splitModuleProxyHandler = { #endif var imports = {'primary': wasmExports}; // Replace '.wasm' suffix with '.deferred.wasm'. - loadSplitModule(secondaryFile, imports, base); + var deferred = wasmBinaryFile.slice(0, -5) + '.deferred.wasm' + loadSplitModule(deferred, imports, base); #if RUNTIME_DEBUG dbg('instantiated deferred module, continuing'); #endif From 67e5380b3b9fc1f3e77f2b619c7cc6b12cc3a9d0 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 15 Oct 2025 23:58:34 +0000 Subject: [PATCH 14/17] Anonymize the inner handler --- src/preamble.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/preamble.js b/src/preamble.js index 4226ea800efe3..145964a2bf704 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -490,7 +490,7 @@ async function getWasmBinary(binaryFile) { var splitModuleProxyHandler = { get(target, moduleName, receiver) { if (moduleName.startsWith('placeholder')) { - var innerHandler = { + return new Proxy({}, { get(target, base, receiver) { return (...args) => { #if ASYNCIFY == 2 @@ -517,8 +517,7 @@ var splitModuleProxyHandler = { #endif } } - }; - return new Proxy({}, innerHandler); + }); } return target[moduleName]; } From 13f034dc3895ebdb53c3620e50a763b41f890e6d Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Thu, 16 Oct 2025 00:05:20 +0000 Subject: [PATCH 15/17] Remove a newline added by mistake --- src/preamble.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/preamble.js b/src/preamble.js index 145964a2bf704..a8c91274d6e6c 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -645,7 +645,6 @@ async function instantiateAsync(binary, binaryFile, imports) { #endif // SOURCE_PHASE_IMPORTS #if !WASM_ESM_INTEGRATION - function getWasmImports() { #if PTHREADS || WASM_WORKERS || (IMPORTED_MEMORY && MODULARIZE == 'instance') assignWasmImports(); From d0a19db38270ccc275a5a50df062203cabe4a7ce Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Thu, 16 Oct 2025 00:31:38 +0000 Subject: [PATCH 16/17] Automatic rebaseline of codesize expectations. NFC This is an automatic change generated by tools/maint/rebaseline_tests.py. The following (5) test expectation files were updated by running the tests with `--rebaseline`: ``` codesize/test_codesize_cxx_wasmfs.json: 176780 => 176780 [+0 bytes / +0.00%] codesize/test_codesize_files_wasmfs.json: 55683 => 55683 [+0 bytes / +0.00%] codesize/test_codesize_hello_O0.json: 39197 => 39189 [-8 bytes / -0.02%] codesize/test_codesize_hello_dylink_all.json: 843553 => 843559 [+6 bytes / +0.00%] codesize/test_unoptimized_code_size.json: 180314 => 180290 [-24 bytes / -0.01%] Average change: -0.01% (-0.02% - +0.00%) ``` --- test/codesize/test_codesize_cxx_wasmfs.json | 4 ++-- test/codesize/test_codesize_files_wasmfs.json | 4 ++-- test/codesize/test_codesize_hello_O0.json | 8 ++++---- .../codesize/test_codesize_hello_dylink_all.json | 4 ++-- test/codesize/test_unoptimized_code_size.json | 16 ++++++++-------- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/test/codesize/test_codesize_cxx_wasmfs.json b/test/codesize/test_codesize_cxx_wasmfs.json index 3b2be1f142d31..3021f01f12876 100644 --- a/test/codesize/test_codesize_cxx_wasmfs.json +++ b/test/codesize/test_codesize_cxx_wasmfs.json @@ -2,9 +2,9 @@ "a.out.js": 7059, "a.out.js.gz": 3330, "a.out.nodebug.wasm": 169721, - "a.out.nodebug.wasm.gz": 62983, + "a.out.nodebug.wasm.gz": 62981, "total": 176780, - "total_gz": 66313, + "total_gz": 66311, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_files_wasmfs.json b/test/codesize/test_codesize_files_wasmfs.json index 5497bd2b1ee39..fb687e208a871 100644 --- a/test/codesize/test_codesize_files_wasmfs.json +++ b/test/codesize/test_codesize_files_wasmfs.json @@ -2,9 +2,9 @@ "a.out.js": 5465, "a.out.js.gz": 2576, "a.out.nodebug.wasm": 50218, - "a.out.nodebug.wasm.gz": 18082, + "a.out.nodebug.wasm.gz": 18086, "total": 55683, - "total_gz": 20658, + "total_gz": 20662, "sent": [ "a (emscripten_date_now)", "b (emscripten_err)", diff --git a/test/codesize/test_codesize_hello_O0.json b/test/codesize/test_codesize_hello_O0.json index 3586b686893df..701ff3b943459 100644 --- a/test/codesize/test_codesize_hello_O0.json +++ b/test/codesize/test_codesize_hello_O0.json @@ -1,10 +1,10 @@ { "a.out.js": 24070, "a.out.js.gz": 8666, - "a.out.nodebug.wasm": 15127, - "a.out.nodebug.wasm.gz": 7450, - "total": 39197, - "total_gz": 16116, + "a.out.nodebug.wasm": 15119, + "a.out.nodebug.wasm.gz": 7444, + "total": 39189, + "total_gz": 16110, "sent": [ "fd_write" ], diff --git a/test/codesize/test_codesize_hello_dylink_all.json b/test/codesize/test_codesize_hello_dylink_all.json index aa27e63c7d228..05ebe029c71ac 100644 --- a/test/codesize/test_codesize_hello_dylink_all.json +++ b/test/codesize/test_codesize_hello_dylink_all.json @@ -1,7 +1,7 @@ { "a.out.js": 245829, - "a.out.nodebug.wasm": 597724, - "total": 843553, + "a.out.nodebug.wasm": 597730, + "total": 843559, "sent": [ "IMG_Init", "IMG_Load", diff --git a/test/codesize/test_unoptimized_code_size.json b/test/codesize/test_unoptimized_code_size.json index c583e5c655fb6..ae60057550c37 100644 --- a/test/codesize/test_unoptimized_code_size.json +++ b/test/codesize/test_unoptimized_code_size.json @@ -1,16 +1,16 @@ { "hello_world.js": 56592, "hello_world.js.gz": 17608, - "hello_world.wasm": 15127, - "hello_world.wasm.gz": 7450, + "hello_world.wasm": 15119, + "hello_world.wasm.gz": 7444, "no_asserts.js": 26634, "no_asserts.js.gz": 8883, - "no_asserts.wasm": 12227, - "no_asserts.wasm.gz": 6010, + "no_asserts.wasm": 12219, + "no_asserts.wasm.gz": 6005, "strict.js": 54607, "strict.js.gz": 16955, - "strict.wasm": 15127, - "strict.wasm.gz": 7447, - "total": 180314, - "total_gz": 64353 + "strict.wasm": 15119, + "strict.wasm.gz": 7442, + "total": 180290, + "total_gz": 64337 } From 6bb859f7c83bdc66a35c596142f66496442a3cfc Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Thu, 16 Oct 2025 16:25:06 +0000 Subject: [PATCH 17/17] Automatic rebaseline of codesize expectations. NFC This is an automatic change generated by tools/maint/rebaseline_tests.py. The following (1) test expectation files were updated by running the tests with `--rebaseline`: ``` codesize/test_unoptimized_code_size.json: 180212 => 180290 [+78 bytes / +0.04%] Average change: +0.04% (+0.04% - +0.04%) ``` --- test/codesize/test_unoptimized_code_size.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/codesize/test_unoptimized_code_size.json b/test/codesize/test_unoptimized_code_size.json index c176785aaee1c..ae60057550c37 100644 --- a/test/codesize/test_unoptimized_code_size.json +++ b/test/codesize/test_unoptimized_code_size.json @@ -1,16 +1,16 @@ { - "hello_world.js": 56566, - "hello_world.js.gz": 17601, + "hello_world.js": 56592, + "hello_world.js.gz": 17608, "hello_world.wasm": 15119, "hello_world.wasm.gz": 7444, - "no_asserts.js": 26608, - "no_asserts.js.gz": 8874, + "no_asserts.js": 26634, + "no_asserts.js.gz": 8883, "no_asserts.wasm": 12219, "no_asserts.wasm.gz": 6005, - "strict.js": 54581, - "strict.js.gz": 16947, + "strict.js": 54607, + "strict.js.gz": 16955, "strict.wasm": 15119, "strict.wasm.gz": 7442, - "total": 180212, - "total_gz": 64313 + "total": 180290, + "total_gz": 64337 }