From d9257b984641c1707c22c69d601c8769e82daf63 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Tue, 7 Jul 2026 21:44:48 +0000 Subject: [PATCH 1/6] Include heap views only when needed Previously, all standard heap views (HEAP8 through HEAPF64) were always included in the JS bundle and initialized, even when unused. This increased bundle size and memory overhead. Remove heap view symbols from default library inclusions. Only include and initialize heap views that are required by runtime features, exported, or referenced in user code and snippets. --- src/jsifier.mjs | 67 +++++++++++++++++++++++++++++++++++++++++++ src/runtime_common.js | 41 +++++++++++++++----------- src/settings.js | 4 +++ tools/emscripten.py | 1 + tools/link.py | 7 ----- 5 files changed, 97 insertions(+), 23 deletions(-) diff --git a/src/jsifier.mjs b/src/jsifier.mjs index 84dc251827b75..5afef3b32fcda 100644 --- a/src/jsifier.mjs +++ b/src/jsifier.mjs @@ -247,12 +247,70 @@ function addImplicitDeps(snippet, deps) { 'runtimeKeepalivePush', 'runtimeKeepalivePop', 'UTF8ToString', + 'getValue', + 'setValue', ]; for (const dep of autoDeps) { if (snippet.includes(dep + '(')) { deps.push('$' + dep); } } + if (snippet.includes('eval(')) { + deps.push('$HEAP8', '$HEAPU8', '$HEAP16', '$HEAPU16', '$HEAP32', '$HEAPU32', '$HEAPF32', '$HEAPF64'); + if (WASM_BIGINT || MEMORY64) { + deps.push('$HEAP64', '$HEAPU64'); + } + } + const heapDeps = [ + 'HEAP8', 'HEAP16', 'HEAPU8', 'HEAPU16', + 'HEAP32', 'HEAPU32', 'HEAPF32', 'HEAPF64', + 'HEAP64', 'HEAPU64', + ]; + for (const heap of heapDeps) { + if (snippet.includes(heap)) { + deps.push('$' + heap); + } + } +} + +// Auto-include heap views and helper symbols required by certain build modes or runtime +// scaffolding files (e.g., postamble.js, runtime_stack_check.js, memoryprofiler.js). +// Because addImplicitDeps only scans library functions and user code (pre-js/post-js/EM_JS), +// runtime scaffolding files that access linear memory directly must have their heap views +// explicitly declared here so they are emitted in the final JS bundle. +function getRequiredHeapSymbols() { + const heaps = new Set(); + if (MAIN_MODULE || EXPORT_ALL || SAFE_HEAP) { + // Dynamic linking side modules, full symbol exports, or safe heap instrumentation + // require all standard heap views and value helpers to be available. + heaps.add('$getValue').add('$setValue'); + heaps.add('$HEAP8').add('$HEAPU8').add('$HEAP16').add('$HEAPU16') + .add('$HEAP32').add('$HEAPU32').add('$HEAPF32').add('$HEAPF64'); + if (WASM_BIGINT || MEMORY64) { + heaps.add('$HEAP64').add('$HEAPU64'); + } + } else { + // STACK_OVERFLOW_CHECK accesses HEAP32/HEAPU32 in runtime_stack_check.js. + // MAIN_READS_PARAMS populates argv pointers in linear memory in postamble.js (callMain). + if (STACK_OVERFLOW_CHECK || (HAS_MAIN && MAIN_READS_PARAMS)) { + heaps.add('$HEAP32').add('$HEAPU32'); + if ((HAS_MAIN && MAIN_READS_PARAMS) && (WASM_BIGINT || MEMORY64)) { + heaps.add('$HEAP64').add('$HEAPU64'); + } + } + // MEMORYPROFILER accesses HEAP8 in memoryprofiler.js. + if (MEMORYPROFILER) { + heaps.add('$HEAP8'); + } + // AUDIO_WORKLET accesses HEAP32, HEAPU32, and HEAPF32 in audio_worklet.js. + if (AUDIO_WORKLET) { + heaps.add('$HEAP32').add('$HEAPU32').add('$HEAPF32'); + if (WASM_BIGINT || MEMORY64) { + heaps.add('$HEAP64').add('$HEAPU64'); + } + } + } + return Array.from(heaps); } function sigToArgs(sig) { @@ -408,6 +466,15 @@ export async function runJSify(outputFile, symbolsOnly) { const symbolsNeeded = DEFAULT_LIBRARY_FUNCS_TO_INCLUDE; symbolsNeeded.push(...extraLibraryFuncs); + symbolsNeeded.push(...getRequiredHeapSymbols()); + + for (const fileName of [...PRE_JS_FILES, ...POST_JS_FILES]) { + const content = readFile(fileName); + addImplicitDeps(content, symbolsNeeded); + } + for (const snippet of EM_JS_SNIPPETS) { + addImplicitDeps(snippet, symbolsNeeded); + } for (const sym of EXPORTED_RUNTIME_METHODS) { if ('$' + sym in LibraryManager.library) { symbolsNeeded.push('$' + sym); diff --git a/src/runtime_common.js b/src/runtime_common.js index ae1474b25706e..6ba365317e492 100644 --- a/src/runtime_common.js +++ b/src/runtime_common.js @@ -17,7 +17,7 @@ // must be updated. function growMemViews() { // `updateMemoryViews` updates all the views simultaneously, so it's enough to check any of them. - if (wasmMemory.buffer != HEAP8.buffer) { + if (typeof HEAP8 != 'undefined' && wasmMemory.buffer != HEAP8.buffer) { updateMemoryViews(); } } @@ -99,13 +99,22 @@ var runtimeExited = false; shouldExport = true; } return shouldExport; - } + }; const maybeExportHeap = (x) => { if (shouldExportHeap(x) && MODULARIZE != 'instance') { return `Module['${x}'] = `; } return ''; }; + const isHeapNeeded = (x) => { + return shouldExportHeap(x) || addedLibraryItems['$' + x]; + }; + const updateHeap = (x, type) => { + if (isHeapNeeded(x)) { + return `${maybeExportHeap(x)}${x} = new ${type}(b);`; + } + return ''; + }; }}} @@ -143,35 +152,35 @@ function getMemoryBuffer() { function updateMemoryViews() { #if RUNTIME_DEBUG - dbg(`updateMemoryViews: first=${!HEAP8} size=${wasmMemory.buffer.byteLength}`); + dbg(`updateMemoryViews: first=${typeof HEAP8 == 'undefined' || !HEAP8} size=${wasmMemory.buffer.byteLength}`); #endif #if ALLOW_MEMORY_GROWTH // If we already have a heap that is resizeable/growable buffer we don't // need to do anything in updateMemoryViews. #if SHARED_MEMORY - if (HEAP8?.buffer?.growable) return; + if (typeof HEAP8 != 'undefined' && HEAP8?.buffer?.growable) return; #else - if (HEAP8?.buffer?.resizable) return; + if (typeof HEAP8 != 'undefined' && HEAP8?.buffer?.resizable) return; #endif var b = getMemoryBuffer(); #else #if ASSERTIONS // When memory growth is disabled this function should be called exactly once. - assert(!HEAP8, 'updateMemoryViews should only be called once when ALLOW_MEMORY_GROWTH=0'); + assert(typeof HEAP8 == 'undefined' || !HEAP8, 'updateMemoryViews should only be called once when ALLOW_MEMORY_GROWTH=0'); #endif var b = wasmMemory.buffer; #endif - {{{ maybeExportHeap('HEAP8') }}}HEAP8 = new Int8Array(b); - {{{ maybeExportHeap('HEAP16') }}}HEAP16 = new Int16Array(b); - {{{ maybeExportHeap('HEAPU8') }}}HEAPU8 = new Uint8Array(b); - {{{ maybeExportHeap('HEAPU16') }}}HEAPU16 = new Uint16Array(b); - {{{ maybeExportHeap('HEAP32') }}}HEAP32 = new Int32Array(b); - {{{ maybeExportHeap('HEAPU32') }}}HEAPU32 = new Uint32Array(b); - {{{ maybeExportHeap('HEAPF32') }}}HEAPF32 = new Float32Array(b); - {{{ maybeExportHeap('HEAPF64') }}}HEAPF64 = new Float64Array(b); + {{{ updateHeap('HEAP8', 'Int8Array') }}} + {{{ updateHeap('HEAP16', 'Int16Array') }}} + {{{ updateHeap('HEAPU8', 'Uint8Array') }}} + {{{ updateHeap('HEAPU16', 'Uint16Array') }}} + {{{ updateHeap('HEAP32', 'Int32Array') }}} + {{{ updateHeap('HEAPU32', 'Uint32Array') }}} + {{{ updateHeap('HEAPF32', 'Float32Array') }}} + {{{ updateHeap('HEAPF64', 'Float64Array') }}} #if WASM_BIGINT - {{{ maybeExportHeap('HEAP64') }}}HEAP64 = new BigInt64Array(b); - {{{ maybeExportHeap('HEAPU64') }}}HEAPU64 = new BigUint64Array(b); + {{{ updateHeap('HEAP64', 'BigInt64Array') }}} + {{{ updateHeap('HEAPU64', 'BigUint64Array') }}} #endif #if SUPPORT_BIG_ENDIAN {{{ maybeExportHeap('HEAP_DATA_VIEW') }}} HEAP_DATA_VIEW = new DataView(b); diff --git a/src/settings.js b/src/settings.js index 24c88a7be4749..063bbe353a417 100644 --- a/src/settings.js +++ b/src/settings.js @@ -2335,3 +2335,7 @@ var FAKE_DYLIBS = false; // This setting can also be set to a string value, in which case that string // will be used as the #! command to embed in the generated file. var EXECUTABLE = false; + +// Internal setting for passing EM_JS and EM_ASM function code snippets to JSifier. +// [internal] +var EM_JS_SNIPPETS = []; diff --git a/tools/emscripten.py b/tools/emscripten.py index fd3f53f93db33..4c3dd367b56f1 100644 --- a/tools/emscripten.py +++ b/tools/emscripten.py @@ -390,6 +390,7 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True, base_metadat asm_consts = create_asm_consts(metadata) em_js_funcs = create_em_js(metadata) + settings.EM_JS_SNIPPETS = em_js_funcs + [f for _, f in asm_consts] if settings.SIDE_MODULE: # When building side modules, validate the EM_ASM and EM_JS string by running diff --git a/tools/link.py b/tools/link.py index db52cd9ced9ba..d336c4d82eae2 100644 --- a/tools/link.py +++ b/tools/link.py @@ -1196,8 +1196,6 @@ def limit_incoming_module_api(): settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += [ '$wasmMemory', - '$HEAP8', '$HEAPU8', '$HEAP16', '$HEAPU16', - '$HEAP32', '$HEAPU32', '$HEAPF32', '$HEAPF64', ] if 'noExitRuntime' in settings.INCOMING_MODULE_JS_API: @@ -1273,8 +1271,6 @@ def limit_incoming_module_api(): # "checkUnflushedContent()" and "missingLibrarySymbol()" depend on warnOnce settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$warnOnce'] - settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$getValue', '$setValue'] - settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$ExitStatus'] if settings.LOAD_SOURCE_MAP: @@ -1573,9 +1569,6 @@ def limit_incoming_module_api(): feature_matrix.auto_enable_features() - if settings.WASM_BIGINT: - settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$HEAP64', '$HEAPU64'] - if settings.AUDIO_WORKLET: add_system_js_lib('libwebaudio.js') settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.append('$getWasmTableEntry') From 07a2029f2d2e2005d94ba36cb4c3eefaf7619d66 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Tue, 7 Jul 2026 22:47:08 +0000 Subject: [PATCH 2/6] Automatic rebaseline of codesize expectations. NFC This is an automatic change generated by tools/maint/rebaseline_tests.py. The following (62) test expectation files were updated by running the tests with `--rebaseline`: ``` test/codesize/audio_worklet_wasm.expected.js updated test/codesize/hello_wasm_worker_wasm.expected.js updated test/codesize/hello_world_wasm.expected.js updated test/codesize/hello_world_wasm2js.expected.js updated codesize/test_codesize_cxx_ctors1.json: 151786 => 151686 [-100 bytes / -0.07%] codesize/test_codesize_cxx_ctors2.json: 151189 => 151089 [-100 bytes / -0.07%] codesize/test_codesize_cxx_except.json: 195681 => 195582 [-99 bytes / -0.05%] codesize/test_codesize_cxx_except_wasm.json: 166910 => 166810 [-100 bytes / -0.06%] codesize/test_codesize_cxx_except_wasm_legacy.json: 164794 => 164694 [-100 bytes / -0.06%] codesize/test_codesize_cxx_lto.json: 120616 => 120516 [-100 bytes / -0.08%] codesize/test_codesize_cxx_mangle.json: 262160 => 262061 [-99 bytes / -0.04%] codesize/test_codesize_cxx_noexcept.json: 153786 => 153686 [-100 bytes / -0.07%] codesize/test_codesize_cxx_wasmfs.json: 179554 => 179433 [-121 bytes / -0.07%] test/codesize/test_codesize_file_preload.expected.js updated codesize/test_codesize_file_preload.json: 23905 => 23806 [-99 bytes / -0.41%] codesize/test_codesize_files_js_fs.json: 18212 => 18112 [-100 bytes / -0.55%] codesize/test_codesize_files_wasmfs.json: 63764 => 63585 [-179 bytes / -0.28%] codesize/test_codesize_hello_O0.json: 38701 => 38554 [-147 bytes / -0.38%] codesize/test_codesize_hello_O1.json: 8261 => 8066 [-195 bytes / -2.36%] codesize/test_codesize_hello_O2.json: 5927 => 5771 [-156 bytes / -2.63%] codesize/test_codesize_hello_O3.json: 5622 => 5467 [-155 bytes / -2.76%] codesize/test_codesize_hello_Os.json: 5610 => 5455 [-155 bytes / -2.76%] codesize/test_codesize_hello_Oz.json: 4781 => 4626 [-155 bytes / -3.24%] codesize/test_codesize_hello_dylink.json: 44051 => 44052 [+1 bytes / +0.00%] codesize/test_codesize_hello_export_nothing.json: 2899 => 2685 [-214 bytes / -7.38%] codesize/test_codesize_hello_single_file.json: 5008 => 4853 [-155 bytes / -3.10%] codesize/test_codesize_hello_wasmfs.json: 5622 => 5467 [-155 bytes / -2.76%] codesize/test_codesize_libcxxabi_message_O3.json: 3312 => 3099 [-213 bytes / -6.43%] codesize/test_codesize_libcxxabi_message_O3_standalone.json: 3493 => 3380 [-113 bytes / -3.24%] codesize/test_codesize_mem_O3.json: 9290 => 9196 [-94 bytes / -1.01%] codesize/test_codesize_mem_O3_grow.json: 9608 => 9539 [-69 bytes / -0.72%] codesize/test_codesize_mem_O3_grow_standalone.json: 9454 => 9382 [-72 bytes / -0.76%] codesize/test_codesize_mem_O3_standalone.json: 9289 => 9193 [-96 bytes / -1.03%] codesize/test_codesize_mem_O3_standalone_lib.json: 8503 => 8390 [-113 bytes / -1.33%] codesize/test_codesize_mem_O3_standalone_narg.json: 8625 => 8512 [-113 bytes / -1.31%] codesize/test_codesize_mem_O3_standalone_narg_flto.json: 7556 => 7443 [-113 bytes / -1.50%] codesize/test_codesize_minimal_64.json: 2600 => 2388 [-212 bytes / -8.15%] test/codesize/test_codesize_minimal_O0.expected.js updated codesize/test_codesize_minimal_O0.json: 19805 => 19650 [-155 bytes / -0.78%] codesize/test_codesize_minimal_O1.json: 3376 => 3119 [-257 bytes / -7.61%] codesize/test_codesize_minimal_O2.json: 2549 => 2332 [-217 bytes / -8.51%] codesize/test_codesize_minimal_O3.json: 2285 => 2073 [-212 bytes / -9.28%] codesize/test_codesize_minimal_Os.json: 2285 => 2073 [-212 bytes / -9.28%] codesize/test_codesize_minimal_Os_mr.json: 577 => 353 [-224 bytes / -38.82%] codesize/test_codesize_minimal_Oz-ctors.json: 2256 => 2044 [-212 bytes / -9.40%] codesize/test_codesize_minimal_Oz.json: 2285 => 2073 [-212 bytes / -9.28%] codesize/test_codesize_minimal_esm.json: 2423 => 2212 [-211 bytes / -8.71%] codesize/test_codesize_minimal_pthreads.json: 26008 => 25912 [-96 bytes / -0.37%] codesize/test_codesize_minimal_pthreads_memgrowth.json: 26443 => 26402 [-41 bytes / -0.16%] codesize/test_codesize_minimal_wasmfs.json: 2285 => 2073 [-212 bytes / -9.28%] codesize/test_minimal_runtime_code_size_hello_embind.json: 14896 => 14896 [+0 bytes / +0.00%] codesize/test_minimal_runtime_code_size_hello_embind_val.json: 11635 => 11635 [+0 bytes / +0.00%] codesize/test_minimal_runtime_code_size_hello_wasm_worker.json: 4121 => 4099 [-22 bytes / -0.53%] codesize/test_minimal_runtime_code_size_hello_webgl2_wasm2js.json: 18559 => 18559 [+0 bytes / +0.00%] codesize/test_minimal_runtime_code_size_hello_webgl2_wasm_singlefile.json: 15040 => 15040 [+0 bytes / +0.00%] codesize/test_minimal_runtime_code_size_hello_webgl_wasm.json: 12724 => 12724 [+0 bytes / +0.00%] codesize/test_minimal_runtime_code_size_hello_world_wasm.json: 927 => 927 [+0 bytes / +0.00%] codesize/test_minimal_runtime_code_size_random_printf_wasm.json: 11054 => 11054 [+0 bytes / +0.00%] codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json: 17417 => 17417 [+0 bytes / +0.00%] test/codesize/test_small_js_flags.expected.js updated codesize/test_small_js_flags.json: 3888 => 3732 [-156 bytes / -4.01%] codesize/test_unoptimized_code_size.json: 177452 => 172027 [-5425 bytes / -3.06%] Average change: -3.16% (-38.82% - +0.00%) ``` --- test/codesize/audio_worklet_wasm.expected.js | 2 +- .../hello_wasm_worker_wasm.expected.js | 75 +++++++------- test/codesize/hello_world_wasm.expected.js | 14 +-- test/codesize/hello_world_wasm2js.expected.js | 8 +- test/codesize/test_codesize_cxx_ctors1.json | 8 +- test/codesize/test_codesize_cxx_ctors2.json | 8 +- test/codesize/test_codesize_cxx_except.json | 8 +- .../test_codesize_cxx_except_wasm.json | 8 +- .../test_codesize_cxx_except_wasm_legacy.json | 8 +- test/codesize/test_codesize_cxx_lto.json | 8 +- test/codesize/test_codesize_cxx_mangle.json | 8 +- test/codesize/test_codesize_cxx_noexcept.json | 8 +- test/codesize/test_codesize_cxx_wasmfs.json | 8 +- .../test_codesize_file_preload.expected.js | 35 ++----- test/codesize/test_codesize_file_preload.json | 8 +- test/codesize/test_codesize_files_js_fs.json | 8 +- test/codesize/test_codesize_files_wasmfs.json | 8 +- test/codesize/test_codesize_hello_O0.json | 8 +- test/codesize/test_codesize_hello_O1.json | 8 +- test/codesize/test_codesize_hello_O2.json | 8 +- test/codesize/test_codesize_hello_O3.json | 8 +- test/codesize/test_codesize_hello_Os.json | 8 +- test/codesize/test_codesize_hello_Oz.json | 8 +- test/codesize/test_codesize_hello_dylink.json | 8 +- .../test_codesize_hello_export_nothing.json | 8 +- .../test_codesize_hello_single_file.json | 4 +- test/codesize/test_codesize_hello_wasmfs.json | 8 +- .../test_codesize_libcxxabi_message_O3.json | 8 +- ...esize_libcxxabi_message_O3_standalone.json | 8 +- test/codesize/test_codesize_mem_O3.json | 8 +- test/codesize/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/codesize/test_codesize_minimal_64.json | 8 +- .../test_codesize_minimal_O0.expected.js | 99 ++++--------------- test/codesize/test_codesize_minimal_O0.json | 8 +- test/codesize/test_codesize_minimal_O1.json | 8 +- test/codesize/test_codesize_minimal_O2.json | 8 +- test/codesize/test_codesize_minimal_O3.json | 8 +- test/codesize/test_codesize_minimal_Os.json | 8 +- .../codesize/test_codesize_minimal_Os_mr.json | 8 +- .../test_codesize_minimal_Oz-ctors.json | 8 +- test/codesize/test_codesize_minimal_Oz.json | 8 +- test/codesize/test_codesize_minimal_esm.json | 8 +- .../test_codesize_minimal_pthreads.json | 8 +- ...t_codesize_minimal_pthreads_memgrowth.json | 8 +- .../test_codesize_minimal_wasmfs.json | 8 +- ...inimal_runtime_code_size_hello_embind.json | 4 +- ...al_runtime_code_size_hello_embind_val.json | 4 +- ...l_runtime_code_size_hello_wasm_worker.json | 8 +- ...untime_code_size_hello_webgl2_wasm2js.json | 4 +- ...ode_size_hello_webgl2_wasm_singlefile.json | 2 +- ...al_runtime_code_size_hello_webgl_wasm.json | 4 +- ...al_runtime_code_size_hello_world_wasm.json | 4 +- ..._runtime_code_size_random_printf_wasm.json | 2 +- ...ntime_code_size_random_printf_wasm2js.json | 2 +- test/codesize/test_small_js_flags.expected.js | 32 +----- test/codesize/test_small_js_flags.json | 8 +- test/codesize/test_unoptimized_code_size.json | 16 +-- 62 files changed, 282 insertions(+), 389 deletions(-) diff --git a/test/codesize/audio_worklet_wasm.expected.js b/test/codesize/audio_worklet_wasm.expected.js index 9ed7b1108c88e..ef048b80670f1 100644 --- a/test/codesize/audio_worklet_wasm.expected.js +++ b/test/codesize/audio_worklet_wasm.expected.js @@ -1,4 +1,4 @@ -var m = globalThis.Module || typeof Module != "undefined" ? Module : {}, r = !!globalThis.WorkerGlobalScope, t = !!globalThis.AudioWorkletGlobalScope, u = globalThis.name == "em-ww" || t, v, K, E, G, J, x, W, P, F, D, C, X, A, Z, H; +var m = globalThis.Module || typeof Module != "undefined" ? Module : {}, r = !!globalThis.WorkerGlobalScope, t = !!globalThis.AudioWorkletGlobalScope, u = globalThis.name == "em-ww" || t, v, x, J, K, G, E, W, P, F, D, C, X, A, Z, H; function w(a) { v = a; diff --git a/test/codesize/hello_wasm_worker_wasm.expected.js b/test/codesize/hello_wasm_worker_wasm.expected.js index a212f66c66b87..5fc571366f86b 100644 --- a/test/codesize/hello_wasm_worker_wasm.expected.js +++ b/test/codesize/hello_wasm_worker_wasm.expected.js @@ -1,80 +1,77 @@ -var c = Module, d = !!globalThis.WorkerGlobalScope, e = globalThis.name == "em-ww", f, g, C, q, D, m, E, v; +var c = Module, d = !!globalThis.WorkerGlobalScope, e = globalThis.name == "em-ww", f, g, B, p, C, l, D, u; e && (onmessage = a => { onmessage = null; f = a = a.data; g = a.o; - h(); c ||= {}; c.wasm = a.m; - k(); + h(); a.m = a.o = 0; }); -function h() {} - e || (g = new WebAssembly.Memory({ initial: 256, maximum: 256, shared: !0 -}), h()); +})); -var l = [], n = a => { +var k = [], m = a => { a = a.data; var b = a._wsc; - b && m.get(b)(...a.x); -}, p = a => { - l.push(a); -}, r = () => { - q(0, !d, !e, d && 1); -}, u = {}, w = (a, b, z) => { - var t = u[a] = new Worker(c.js, { + b && l.get(b)(...a.x); +}, n = a => { + k.push(a); +}, q = () => { + p(0, !d, !e, d && 1); +}, t = {}, v = (a, b, y) => { + var r = t[a] = new Worker(c.js, { name: "em-ww" }); - t.postMessage({ + r.postMessage({ A: a, - m: v, + m: u, o: g, u: b, - v: z + v: y }); - t.onmessage = n; + r.onmessage = m; return !0; -}, x = () => performance.now(), y = () => !1, A = (a, b) => { - u[a].postMessage({ +}, w = () => performance.now(), x = () => !1, z = (a, b) => { + t[a].postMessage({ _wsc: b, x: [] }); }; -e && (u[0] = globalThis, addEventListener("message", p)); +e && (t[0] = globalThis, addEventListener("message", n)); -function B() { +function A() { console.log("Hello from wasm worker!"); } -function k() { - E = { - d: r, - c: w, - b: x, - e: y, - f: A, - g: B, +function h() { + D = { + d: q, + c: v, + b: w, + e: x, + f: z, + g: A, a: g }; WebAssembly.instantiate(c.wasm, { - a: E + a: D }).then((a => { var b = (a.instance || a).exports; - v = a.module || c.wasm; - C = b.i; - q = b.k; - D = b.l; - m = b.j; - e ? (D(f.A, f.u, f.v), removeEventListener("message", p), l = l.forEach(n), addEventListener("message", n)) : b.h(); - e || C(); + u = a.module || c.wasm; + B = b.i; + p = b.k; + C = b.l; + l = b.j; + e ? (C(f.A, f.u, f.v), removeEventListener("message", n), k = k.forEach(m), addEventListener("message", m)) : b.h(); + e || B(); })); } -e || k(); \ No newline at end of file +e || h(); \ No newline at end of file diff --git a/test/codesize/hello_world_wasm.expected.js b/test/codesize/hello_world_wasm.expected.js index cb72d2838de31..1cd54e114ae98 100644 --- a/test/codesize/hello_world_wasm.expected.js +++ b/test/codesize/hello_world_wasm.expected.js @@ -1,21 +1,21 @@ -var d = Module, e, f = new TextDecoder, g, h; +var c = Module, d = new TextDecoder, e, f, h; -WebAssembly.instantiate(d.wasm, { +WebAssembly.instantiate(c.wasm, { a: { a: a => { - var c = console, k = c.log; + var g = console, k = g.log; if (a) { for (var b = a, l = e, m = b + NaN; l[b] && !(b >= m); ) ++b; - a = f.decode(e.subarray(a, b)); + a = d.decode(e.subarray(a, b)); } else a = ""; - k.call(c, a); + k.call(g, a); } } }).then((a => { a = a.instance.exports; - g = a.d; + f = a.d; h = a.b; e = new Uint8Array(h.buffer); a.c(); - g(); + f(); })); \ No newline at end of file diff --git a/test/codesize/hello_world_wasm2js.expected.js b/test/codesize/hello_world_wasm2js.expected.js index d23d8bf32480c..5593170066940 100644 --- a/test/codesize/hello_world_wasm2js.expected.js +++ b/test/codesize/hello_world_wasm2js.expected.js @@ -1,4 +1,4 @@ -var d = Module, g, h = new TextDecoder, k, l; +var d = Module, g = new TextDecoder, h, k, l; function e(a) { this.exports = function(q) { @@ -48,8 +48,8 @@ function e(a) { a: a => { var q = console, u = q.log; if (a) { - for (var n = a, c = g, f = n + void 0; c[n] && !(n >= f); ) ++n; - a = h.decode(g.subarray(a, n)); + for (var n = a, c = h, f = n + void 0; c[n] && !(n >= f); ) ++n; + a = g.decode(h.subarray(a, n)); } else a = ""; u.call(q, a); } @@ -58,7 +58,7 @@ function e(a) { a = a.instance.exports; k = a.d; l = a.b; - g = new Uint8Array(l.buffer); + h = new Uint8Array(l.buffer); a.c(); k(); })); \ No newline at end of file diff --git a/test/codesize/test_codesize_cxx_ctors1.json b/test/codesize/test_codesize_cxx_ctors1.json index 38da5d7d240f5..cba785f32563f 100644 --- a/test/codesize/test_codesize_cxx_ctors1.json +++ b/test/codesize/test_codesize_cxx_ctors1.json @@ -1,10 +1,10 @@ { - "a.out.js": 19183, - "a.out.js.gz": 7971, + "a.out.js": 19083, + "a.out.js.gz": 7947, "a.out.nodebug.wasm": 132603, "a.out.nodebug.wasm.gz": 49939, - "total": 151786, - "total_gz": 57910, + "total": 151686, + "total_gz": 57886, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_ctors2.json b/test/codesize/test_codesize_cxx_ctors2.json index a258ca20a58e8..fb5139bc4cbb5 100644 --- a/test/codesize/test_codesize_cxx_ctors2.json +++ b/test/codesize/test_codesize_cxx_ctors2.json @@ -1,10 +1,10 @@ { - "a.out.js": 19160, - "a.out.js.gz": 7957, + "a.out.js": 19060, + "a.out.js.gz": 7931, "a.out.nodebug.wasm": 132029, "a.out.nodebug.wasm.gz": 49599, - "total": 151189, - "total_gz": 57556, + "total": 151089, + "total_gz": 57530, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_except.json b/test/codesize/test_codesize_cxx_except.json index a66355c6521fc..59681c646d649 100644 --- a/test/codesize/test_codesize_cxx_except.json +++ b/test/codesize/test_codesize_cxx_except.json @@ -1,10 +1,10 @@ { - "a.out.js": 23158, - "a.out.js.gz": 8955, + "a.out.js": 23059, + "a.out.js.gz": 8939, "a.out.nodebug.wasm": 172523, "a.out.nodebug.wasm.gz": 57480, - "total": 195681, - "total_gz": 66435, + "total": 195582, + "total_gz": 66419, "sent": [ "__cxa_begin_catch", "__cxa_end_catch", diff --git a/test/codesize/test_codesize_cxx_except_wasm.json b/test/codesize/test_codesize_cxx_except_wasm.json index d6477ceb081bf..3ccfc0e49bdec 100644 --- a/test/codesize/test_codesize_cxx_except_wasm.json +++ b/test/codesize/test_codesize_cxx_except_wasm.json @@ -1,10 +1,10 @@ { - "a.out.js": 18982, - "a.out.js.gz": 7888, + "a.out.js": 18882, + "a.out.js.gz": 7863, "a.out.nodebug.wasm": 147928, "a.out.nodebug.wasm.gz": 55349, - "total": 166910, - "total_gz": 63237, + "total": 166810, + "total_gz": 63212, "sent": [ "_abort_js", "_tzset_js", diff --git a/test/codesize/test_codesize_cxx_except_wasm_legacy.json b/test/codesize/test_codesize_cxx_except_wasm_legacy.json index 19e47699182eb..3221d5672f5e9 100644 --- a/test/codesize/test_codesize_cxx_except_wasm_legacy.json +++ b/test/codesize/test_codesize_cxx_except_wasm_legacy.json @@ -1,10 +1,10 @@ { - "a.out.js": 19060, - "a.out.js.gz": 7913, + "a.out.js": 18960, + "a.out.js.gz": 7888, "a.out.nodebug.wasm": 145734, "a.out.nodebug.wasm.gz": 54976, - "total": 164794, - "total_gz": 62889, + "total": 164694, + "total_gz": 62864, "sent": [ "_abort_js", "_tzset_js", diff --git a/test/codesize/test_codesize_cxx_lto.json b/test/codesize/test_codesize_cxx_lto.json index 249afc77b84a9..66faff6a2b947 100644 --- a/test/codesize/test_codesize_cxx_lto.json +++ b/test/codesize/test_codesize_cxx_lto.json @@ -1,10 +1,10 @@ { - "a.out.js": 18526, - "a.out.js.gz": 7665, + "a.out.js": 18426, + "a.out.js.gz": 7640, "a.out.nodebug.wasm": 102090, "a.out.nodebug.wasm.gz": 39548, - "total": 120616, - "total_gz": 47213, + "total": 120516, + "total_gz": 47188, "sent": [ "a (emscripten_resize_heap)", "b (_setitimer_js)", diff --git a/test/codesize/test_codesize_cxx_mangle.json b/test/codesize/test_codesize_cxx_mangle.json index f0ff9ccf46ce5..3e02365278def 100644 --- a/test/codesize/test_codesize_cxx_mangle.json +++ b/test/codesize/test_codesize_cxx_mangle.json @@ -1,10 +1,10 @@ { - "a.out.js": 23208, - "a.out.js.gz": 8976, + "a.out.js": 23109, + "a.out.js.gz": 8957, "a.out.nodebug.wasm": 238952, "a.out.nodebug.wasm.gz": 79833, - "total": 262160, - "total_gz": 88809, + "total": 262061, + "total_gz": 88790, "sent": [ "__cxa_begin_catch", "__cxa_end_catch", diff --git a/test/codesize/test_codesize_cxx_noexcept.json b/test/codesize/test_codesize_cxx_noexcept.json index 9663f0ff6a578..2ad89c9128e6c 100644 --- a/test/codesize/test_codesize_cxx_noexcept.json +++ b/test/codesize/test_codesize_cxx_noexcept.json @@ -1,10 +1,10 @@ { - "a.out.js": 19183, - "a.out.js.gz": 7971, + "a.out.js": 19083, + "a.out.js.gz": 7947, "a.out.nodebug.wasm": 134603, "a.out.nodebug.wasm.gz": 50779, - "total": 153786, - "total_gz": 58750, + "total": 153686, + "total_gz": 58726, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_wasmfs.json b/test/codesize/test_codesize_cxx_wasmfs.json index 27884b4e8620d..7cadfbb19effa 100644 --- a/test/codesize/test_codesize_cxx_wasmfs.json +++ b/test/codesize/test_codesize_cxx_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 6725, - "a.out.js.gz": 3184, + "a.out.js": 6604, + "a.out.js.gz": 3154, "a.out.nodebug.wasm": 172829, "a.out.nodebug.wasm.gz": 63329, - "total": 179554, - "total_gz": 66513, + "total": 179433, + "total_gz": 66483, "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 97ef63fcb0f09..511f381401533 100644 --- a/test/codesize/test_codesize_file_preload.expected.js +++ b/test/codesize/test_codesize_file_preload.expected.js @@ -317,15 +317,10 @@ var runtimeInitialized = false; function updateMemoryViews() { var b = wasmMemory.buffer; HEAP8 = new Int8Array(b); - HEAP16 = new Int16Array(b); HEAPU8 = new Uint8Array(b); - HEAPU16 = new Uint16Array(b); HEAP32 = new Int32Array(b); HEAPU32 = new Uint32Array(b); - HEAPF32 = new Float32Array(b); - HEAPF64 = new Float64Array(b); HEAP64 = new BigInt64Array(b); - HEAPU64 = new BigUint64Array(b); } // include: memoryprofiler.js @@ -484,26 +479,6 @@ class ExitStatus { } } -/** @type {!Int16Array} */ var HEAP16; - -/** @type {!Int32Array} */ var HEAP32; - -/** not-@type {!BigInt64Array} */ var HEAP64; - -/** @type {!Int8Array} */ var HEAP8; - -/** @type {!Float32Array} */ var HEAPF32; - -/** @type {!Float64Array} */ var HEAPF64; - -/** @type {!Uint16Array} */ var HEAPU16; - -/** @type {!Uint32Array} */ var HEAPU32; - -/** not-@type {!BigUint64Array} */ var HEAPU64; - -/** @type {!Uint8Array} */ var HEAPU8; - var callRuntimeCallbacks = callbacks => { while (callbacks.length > 0) { // Pass the module as the first argument. @@ -513,6 +488,10 @@ var callRuntimeCallbacks = callbacks => { var onPreRuns = []; +/** @type {!Int8Array} */ var HEAP8; + +/** @type {!Uint32Array} */ var HEAPU32; + /** @param {number=} offset */ var doWritev = (stream, iov, iovcnt, offset) => { var ret = 0; for (var i = 0; i < iovcnt; i++) { @@ -3032,6 +3011,8 @@ var FS = { } }; +/** @type {!Uint8Array} */ var HEAPU8; + /** * Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the * emscripten HEAP, returns a copy of that string as a Javascript String object. @@ -3046,6 +3027,10 @@ var FS = { * @return {string} */ var UTF8ToString = (ptr, maxBytesToRead, ignoreNul) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead, ignoreNul) : ""; +/** @type {!Int32Array} */ var HEAP32; + +/** not-@type {!BigInt64Array} */ var HEAP64; + var SYSCALLS = { currentUmask: 18, calculateAt(dirfd, path, allowEmpty) { diff --git a/test/codesize/test_codesize_file_preload.json b/test/codesize/test_codesize_file_preload.json index 8f618f019aa71..26fc198071093 100644 --- a/test/codesize/test_codesize_file_preload.json +++ b/test/codesize/test_codesize_file_preload.json @@ -1,10 +1,10 @@ { - "a.out.js": 22239, - "a.out.js.gz": 9251, + "a.out.js": 22140, + "a.out.js.gz": 9232, "a.out.nodebug.wasm": 1666, "a.out.nodebug.wasm.gz": 945, - "total": 23905, - "total_gz": 10196, + "total": 23806, + "total_gz": 10177, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_files_js_fs.json b/test/codesize/test_codesize_files_js_fs.json index 3ff56a1152b6e..f0d4e516fad78 100644 --- a/test/codesize/test_codesize_files_js_fs.json +++ b/test/codesize/test_codesize_files_js_fs.json @@ -1,10 +1,10 @@ { - "a.out.js": 17831, - "a.out.js.gz": 7311, + "a.out.js": 17731, + "a.out.js.gz": 7292, "a.out.nodebug.wasm": 381, "a.out.nodebug.wasm.gz": 258, - "total": 18212, - "total_gz": 7569, + "total": 18112, + "total_gz": 7550, "sent": [ "a (fd_write)", "b (fd_read)", diff --git a/test/codesize/test_codesize_files_wasmfs.json b/test/codesize/test_codesize_files_wasmfs.json index f5c6388f137c7..9f01cfea58449 100644 --- a/test/codesize/test_codesize_files_wasmfs.json +++ b/test/codesize/test_codesize_files_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 5158, - "a.out.js.gz": 2458, + "a.out.js": 4979, + "a.out.js.gz": 2409, "a.out.nodebug.wasm": 58606, "a.out.nodebug.wasm.gz": 18406, - "total": 63764, - "total_gz": 20864, + "total": 63585, + "total_gz": 20815, "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 fa5e682019094..f12bd41a404ed 100644 --- a/test/codesize/test_codesize_hello_O0.json +++ b/test/codesize/test_codesize_hello_O0.json @@ -1,10 +1,10 @@ { - "a.out.js": 23586, - "a.out.js.gz": 8615, + "a.out.js": 23439, + "a.out.js.gz": 8583, "a.out.nodebug.wasm": 15115, "a.out.nodebug.wasm.gz": 7464, - "total": 38701, - "total_gz": 16079, + "total": 38554, + "total_gz": 16047, "sent": [ "fd_write" ], diff --git a/test/codesize/test_codesize_hello_O1.json b/test/codesize/test_codesize_hello_O1.json index a1aad3d6c2fd1..be7c4fe9daa15 100644 --- a/test/codesize/test_codesize_hello_O1.json +++ b/test/codesize/test_codesize_hello_O1.json @@ -1,10 +1,10 @@ { - "a.out.js": 5717, - "a.out.js.gz": 2279, + "a.out.js": 5522, + "a.out.js.gz": 2239, "a.out.nodebug.wasm": 2544, "a.out.nodebug.wasm.gz": 1436, - "total": 8261, - "total_gz": 3715, + "total": 8066, + "total_gz": 3675, "sent": [ "fd_write" ], diff --git a/test/codesize/test_codesize_hello_O2.json b/test/codesize/test_codesize_hello_O2.json index b42281069ef1f..ba874758500df 100644 --- a/test/codesize/test_codesize_hello_O2.json +++ b/test/codesize/test_codesize_hello_O2.json @@ -1,10 +1,10 @@ { - "a.out.js": 4015, - "a.out.js.gz": 2014, + "a.out.js": 3859, + "a.out.js.gz": 1970, "a.out.nodebug.wasm": 1912, "a.out.nodebug.wasm.gz": 1129, - "total": 5927, - "total_gz": 3143, + "total": 5771, + "total_gz": 3099, "sent": [ "fd_write" ], diff --git a/test/codesize/test_codesize_hello_O3.json b/test/codesize/test_codesize_hello_O3.json index 4b0f47f84662e..be2ba272d7006 100644 --- a/test/codesize/test_codesize_hello_O3.json +++ b/test/codesize/test_codesize_hello_O3.json @@ -1,10 +1,10 @@ { - "a.out.js": 3956, - "a.out.js.gz": 1971, + "a.out.js": 3801, + "a.out.js.gz": 1928, "a.out.nodebug.wasm": 1666, "a.out.nodebug.wasm.gz": 945, - "total": 5622, - "total_gz": 2916, + "total": 5467, + "total_gz": 2873, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_hello_Os.json b/test/codesize/test_codesize_hello_Os.json index f47b9a846859a..71749bb323745 100644 --- a/test/codesize/test_codesize_hello_Os.json +++ b/test/codesize/test_codesize_hello_Os.json @@ -1,10 +1,10 @@ { - "a.out.js": 3956, - "a.out.js.gz": 1971, + "a.out.js": 3801, + "a.out.js.gz": 1928, "a.out.nodebug.wasm": 1654, "a.out.nodebug.wasm.gz": 953, - "total": 5610, - "total_gz": 2924, + "total": 5455, + "total_gz": 2881, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_hello_Oz.json b/test/codesize/test_codesize_hello_Oz.json index 3892ef01ed941..85d5d192a160a 100644 --- a/test/codesize/test_codesize_hello_Oz.json +++ b/test/codesize/test_codesize_hello_Oz.json @@ -1,10 +1,10 @@ { - "a.out.js": 3593, - "a.out.js.gz": 1776, + "a.out.js": 3438, + "a.out.js.gz": 1732, "a.out.nodebug.wasm": 1188, "a.out.nodebug.wasm.gz": 731, - "total": 4781, - "total_gz": 2507, + "total": 4626, + "total_gz": 2463, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_hello_dylink.json b/test/codesize/test_codesize_hello_dylink.json index bca58fb7b3b36..1d3e653fe0749 100644 --- a/test/codesize/test_codesize_hello_dylink.json +++ b/test/codesize/test_codesize_hello_dylink.json @@ -1,10 +1,10 @@ { - "a.out.js": 26190, - "a.out.js.gz": 11198, + "a.out.js": 26191, + "a.out.js.gz": 11201, "a.out.nodebug.wasm": 17861, "a.out.nodebug.wasm.gz": 9019, - "total": 44051, - "total_gz": 20217, + "total": 44052, + "total_gz": 20220, "sent": [ "__syscall_stat64", "emscripten_resize_heap", diff --git a/test/codesize/test_codesize_hello_export_nothing.json b/test/codesize/test_codesize_hello_export_nothing.json index 92943bc741178..c4012b3373c4f 100644 --- a/test/codesize/test_codesize_hello_export_nothing.json +++ b/test/codesize/test_codesize_hello_export_nothing.json @@ -1,10 +1,10 @@ { - "a.out.js": 2856, - "a.out.js.gz": 1359, + "a.out.js": 2642, + "a.out.js.gz": 1290, "a.out.nodebug.wasm": 43, "a.out.nodebug.wasm.gz": 59, - "total": 2899, - "total_gz": 1418, + "total": 2685, + "total_gz": 1349, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_hello_single_file.json b/test/codesize/test_codesize_hello_single_file.json index c8a0a2a0ac36e..5903fc859d0f6 100644 --- a/test/codesize/test_codesize_hello_single_file.json +++ b/test/codesize/test_codesize_hello_single_file.json @@ -1,6 +1,6 @@ { - "a.out.js": 5008, - "a.out.js.gz": 2793, + "a.out.js": 4853, + "a.out.js.gz": 2750, "sent": [ "a (fd_write)" ] diff --git a/test/codesize/test_codesize_hello_wasmfs.json b/test/codesize/test_codesize_hello_wasmfs.json index 4b0f47f84662e..be2ba272d7006 100644 --- a/test/codesize/test_codesize_hello_wasmfs.json +++ b/test/codesize/test_codesize_hello_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 3956, - "a.out.js.gz": 1971, + "a.out.js": 3801, + "a.out.js.gz": 1928, "a.out.nodebug.wasm": 1666, "a.out.nodebug.wasm.gz": 945, - "total": 5622, - "total_gz": 2916, + "total": 5467, + "total_gz": 2873, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_libcxxabi_message_O3.json b/test/codesize/test_codesize_libcxxabi_message_O3.json index 767a0d4b776fe..a3d564f5f2563 100644 --- a/test/codesize/test_codesize_libcxxabi_message_O3.json +++ b/test/codesize/test_codesize_libcxxabi_message_O3.json @@ -1,10 +1,10 @@ { - "a.out.js": 3223, - "a.out.js.gz": 1545, + "a.out.js": 3010, + "a.out.js.gz": 1480, "a.out.nodebug.wasm": 89, "a.out.nodebug.wasm.gz": 98, - "total": 3312, - "total_gz": 1643, + "total": 3099, + "total_gz": 1578, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_libcxxabi_message_O3_standalone.json b/test/codesize/test_codesize_libcxxabi_message_O3_standalone.json index 2d66550fe7101..7582dfb485e0e 100644 --- a/test/codesize/test_codesize_libcxxabi_message_O3_standalone.json +++ b/test/codesize/test_codesize_libcxxabi_message_O3_standalone.json @@ -1,10 +1,10 @@ { - "a.out.js": 3271, - "a.out.js.gz": 1579, + "a.out.js": 3158, + "a.out.js.gz": 1555, "a.out.nodebug.wasm": 222, "a.out.nodebug.wasm.gz": 206, - "total": 3493, - "total_gz": 1785, + "total": 3380, + "total_gz": 1761, "sent": [ "proc_exit" ], diff --git a/test/codesize/test_codesize_mem_O3.json b/test/codesize/test_codesize_mem_O3.json index b8826edc16c2e..b88e76157cbb1 100644 --- a/test/codesize/test_codesize_mem_O3.json +++ b/test/codesize/test_codesize_mem_O3.json @@ -1,10 +1,10 @@ { - "a.out.js": 4030, - "a.out.js.gz": 1966, + "a.out.js": 3936, + "a.out.js.gz": 1945, "a.out.nodebug.wasm": 5260, "a.out.nodebug.wasm.gz": 2419, - "total": 9290, - "total_gz": 4385, + "total": 9196, + "total_gz": 4364, "sent": [ "a (emscripten_resize_heap)" ], diff --git a/test/codesize/test_codesize_mem_O3_grow.json b/test/codesize/test_codesize_mem_O3_grow.json index f6bd386c93d8a..4c76b61e549d0 100644 --- a/test/codesize/test_codesize_mem_O3_grow.json +++ b/test/codesize/test_codesize_mem_O3_grow.json @@ -1,10 +1,10 @@ { - "a.out.js": 4347, - "a.out.js.gz": 2138, + "a.out.js": 4278, + "a.out.js.gz": 2123, "a.out.nodebug.wasm": 5261, "a.out.nodebug.wasm.gz": 2419, - "total": 9608, - "total_gz": 4557, + "total": 9539, + "total_gz": 4542, "sent": [ "a (emscripten_resize_heap)" ], diff --git a/test/codesize/test_codesize_mem_O3_grow_standalone.json b/test/codesize/test_codesize_mem_O3_grow_standalone.json index 3190458c7ceae..38a3ec52a1489 100644 --- a/test/codesize/test_codesize_mem_O3_grow_standalone.json +++ b/test/codesize/test_codesize_mem_O3_grow_standalone.json @@ -1,10 +1,10 @@ { - "a.out.js": 3813, - "a.out.js.gz": 1874, + "a.out.js": 3741, + "a.out.js.gz": 1859, "a.out.nodebug.wasm": 5641, "a.out.nodebug.wasm.gz": 2659, - "total": 9454, - "total_gz": 4533, + "total": 9382, + "total_gz": 4518, "sent": [ "args_get", "args_sizes_get", diff --git a/test/codesize/test_codesize_mem_O3_standalone.json b/test/codesize/test_codesize_mem_O3_standalone.json index bca2761225edb..c423ccbfaed0b 100644 --- a/test/codesize/test_codesize_mem_O3_standalone.json +++ b/test/codesize/test_codesize_mem_O3_standalone.json @@ -1,10 +1,10 @@ { - "a.out.js": 3724, - "a.out.js.gz": 1822, + "a.out.js": 3628, + "a.out.js.gz": 1803, "a.out.nodebug.wasm": 5565, "a.out.nodebug.wasm.gz": 2598, - "total": 9289, - "total_gz": 4420, + "total": 9193, + "total_gz": 4401, "sent": [ "args_get", "args_sizes_get", diff --git a/test/codesize/test_codesize_mem_O3_standalone_lib.json b/test/codesize/test_codesize_mem_O3_standalone_lib.json index 874a6a5510cb9..b9429c483376d 100644 --- a/test/codesize/test_codesize_mem_O3_standalone_lib.json +++ b/test/codesize/test_codesize_mem_O3_standalone_lib.json @@ -1,10 +1,10 @@ { - "a.out.js": 3264, - "a.out.js.gz": 1571, + "a.out.js": 3151, + "a.out.js.gz": 1548, "a.out.nodebug.wasm": 5239, "a.out.nodebug.wasm.gz": 2359, - "total": 8503, - "total_gz": 3930, + "total": 8390, + "total_gz": 3907, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_mem_O3_standalone_narg.json b/test/codesize/test_codesize_mem_O3_standalone_narg.json index acb2104805bc2..9c32bec0d90ab 100644 --- a/test/codesize/test_codesize_mem_O3_standalone_narg.json +++ b/test/codesize/test_codesize_mem_O3_standalone_narg.json @@ -1,10 +1,10 @@ { - "a.out.js": 3271, - "a.out.js.gz": 1579, + "a.out.js": 3158, + "a.out.js.gz": 1555, "a.out.nodebug.wasm": 5354, "a.out.nodebug.wasm.gz": 2442, - "total": 8625, - "total_gz": 4021, + "total": 8512, + "total_gz": 3997, "sent": [ "proc_exit" ], diff --git a/test/codesize/test_codesize_mem_O3_standalone_narg_flto.json b/test/codesize/test_codesize_mem_O3_standalone_narg_flto.json index 4fd05e77f282b..7ca5726e90dc9 100644 --- a/test/codesize/test_codesize_mem_O3_standalone_narg_flto.json +++ b/test/codesize/test_codesize_mem_O3_standalone_narg_flto.json @@ -1,10 +1,10 @@ { - "a.out.js": 3271, - "a.out.js.gz": 1579, + "a.out.js": 3158, + "a.out.js.gz": 1555, "a.out.nodebug.wasm": 4285, "a.out.nodebug.wasm.gz": 2142, - "total": 7556, - "total_gz": 3721, + "total": 7443, + "total_gz": 3697, "sent": [ "proc_exit" ], diff --git a/test/codesize/test_codesize_minimal_64.json b/test/codesize/test_codesize_minimal_64.json index 73afa227590d6..337855a8c4b26 100644 --- a/test/codesize/test_codesize_minimal_64.json +++ b/test/codesize/test_codesize_minimal_64.json @@ -1,10 +1,10 @@ { - "a.out.js": 2525, - "a.out.js.gz": 1200, + "a.out.js": 2313, + "a.out.js.gz": 1138, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 88, - "total": 2600, - "total_gz": 1288, + "total": 2388, + "total_gz": 1226, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_O0.expected.js b/test/codesize/test_codesize_minimal_O0.expected.js index f768e93cd3692..185318708bbb8 100644 --- a/test/codesize/test_codesize_minimal_O0.expected.js +++ b/test/codesize/test_codesize_minimal_O0.expected.js @@ -487,18 +487,18 @@ var runtimeInitialized = false; function updateMemoryViews() { // When memory growth is disabled this function should be called exactly once. - assert(!HEAP8, 'updateMemoryViews should only be called once when ALLOW_MEMORY_GROWTH=0'); + assert(typeof HEAP8 == 'undefined' || !HEAP8, 'updateMemoryViews should only be called once when ALLOW_MEMORY_GROWTH=0'); var b = wasmMemory.buffer; - HEAP8 = new Int8Array(b); - HEAP16 = new Int16Array(b); - HEAPU8 = new Uint8Array(b); - HEAPU16 = new Uint16Array(b); + + + + HEAP32 = new Int32Array(b); HEAPU32 = new Uint32Array(b); - HEAPF32 = new Float32Array(b); - HEAPF64 = new Float64Array(b); - HEAP64 = new BigInt64Array(b); - HEAPU64 = new BigUint64Array(b); + + + + } // include: memoryprofiler.js @@ -728,36 +728,6 @@ async function createWasm() { } } - /** @type {!Int16Array} */ - var HEAP16; - - /** @type {!Int32Array} */ - var HEAP32; - - /** not-@type {!BigInt64Array} */ - var HEAP64; - - /** @type {!Int8Array} */ - var HEAP8; - - /** @type {!Float32Array} */ - var HEAPF32; - - /** @type {!Float64Array} */ - var HEAPF64; - - /** @type {!Uint16Array} */ - var HEAPU16; - - /** @type {!Uint32Array} */ - var HEAPU32; - - /** not-@type {!BigUint64Array} */ - var HEAPU64; - - /** @type {!Uint8Array} */ - var HEAPU8; - var callRuntimeCallbacks = (callbacks) => { while (callbacks.length > 0) { // Pass the module as the first argument. @@ -765,26 +735,6 @@ async function createWasm() { } }; - - /** - * @param {number} ptr - * @param {string} type - */ - function getValue(ptr, type = 'i8') { - if (type.endsWith('*')) type = '*'; - switch (type) { - case 'i1': return HEAP8[ptr]; - case 'i8': return HEAP8[ptr]; - case 'i16': return HEAP16[((ptr)>>1)]; - case 'i32': return HEAP32[((ptr)>>2)]; - case 'i64': return HEAP64[((ptr)>>3)]; - case 'float': return HEAPF32[((ptr)>>2)]; - case 'double': return HEAPF64[((ptr)>>3)]; - case '*': return HEAPU32[((ptr)>>2)]; - default: abort(`invalid type for getValue: ${type}`); - } - } - function ptrToString(ptr) { assert(typeof ptr === 'number', `ptrToString expects a number, got ${typeof ptr}`); // Convert to 32-bit unsigned value @@ -792,27 +742,6 @@ async function createWasm() { return '0x' + ptr.toString(16).padStart(8, '0'); } - - /** - * @param {number} ptr - * @param {number} value - * @param {string} type - */ - function setValue(ptr, value, type = 'i8') { - if (type.endsWith('*')) type = '*'; - switch (type) { - case 'i1': HEAP8[ptr] = value; break; - case 'i8': HEAP8[ptr] = value; break; - case 'i16': HEAP16[((ptr)>>1)] = value; break; - case 'i32': HEAP32[((ptr)>>2)] = value; break; - case 'i64': HEAP64[((ptr)>>3)] = BigInt(value); break; - case 'float': HEAPF32[((ptr)>>2)] = value; break; - case 'double': HEAPF64[((ptr)>>3)] = value; break; - case '*': HEAPU32[((ptr)>>2)] = value; break; - default: abort(`invalid type for setValue: ${type}`); - } - } - var stackRestore = (val) => __emscripten_stack_restore(val); var stackSave = () => _emscripten_stack_get_current(); @@ -827,6 +756,12 @@ async function createWasm() { }; + + /** @type {!Int32Array} */ + var HEAP32; + + /** @type {!Uint32Array} */ + var HEAPU32; // End JS library code // include: postlibrary.js @@ -933,6 +868,8 @@ Module['FS_createPreloadedFile'] = FS.createPreloadedFile; 'getFunctionAddress', 'addFunction', 'removeFunction', + 'setValue', + 'getValue', 'UTF8ArrayToString', 'UTF8ToString', 'stringToUTF8Array', @@ -1069,8 +1006,6 @@ missingLibrarySymbols.forEach(missingLibrarySymbol) 'noExitRuntime', 'freeTableIndexes', 'functionsInTableMap', - 'setValue', - 'getValue', 'PATH', 'PATH_FS', 'UTF8Decoder', diff --git a/test/codesize/test_codesize_minimal_O0.json b/test/codesize/test_codesize_minimal_O0.json index 471feccf094c2..11a78d8cd2223 100644 --- a/test/codesize/test_codesize_minimal_O0.json +++ b/test/codesize/test_codesize_minimal_O0.json @@ -1,10 +1,10 @@ { - "a.out.js": 18790, - "a.out.js.gz": 6786, + "a.out.js": 18635, + "a.out.js.gz": 6759, "a.out.nodebug.wasm": 1015, "a.out.nodebug.wasm.gz": 602, - "total": 19805, - "total_gz": 7388, + "total": 19650, + "total_gz": 7361, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_O1.json b/test/codesize/test_codesize_minimal_O1.json index 7614d27da4188..ed105fff59191 100644 --- a/test/codesize/test_codesize_minimal_O1.json +++ b/test/codesize/test_codesize_minimal_O1.json @@ -1,10 +1,10 @@ { - "a.out.js": 2927, - "a.out.js.gz": 1237, + "a.out.js": 2670, + "a.out.js.gz": 1167, "a.out.nodebug.wasm": 449, "a.out.nodebug.wasm.gz": 337, - "total": 3376, - "total_gz": 1574, + "total": 3119, + "total_gz": 1504, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_O2.json b/test/codesize/test_codesize_minimal_O2.json index 9bc333dc5260d..3436eb3b2d8eb 100644 --- a/test/codesize/test_codesize_minimal_O2.json +++ b/test/codesize/test_codesize_minimal_O2.json @@ -1,10 +1,10 @@ { - "a.out.js": 2269, - "a.out.js.gz": 1125, + "a.out.js": 2052, + "a.out.js.gz": 1058, "a.out.nodebug.wasm": 280, "a.out.nodebug.wasm.gz": 226, - "total": 2549, - "total_gz": 1351, + "total": 2332, + "total_gz": 1284, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_O3.json b/test/codesize/test_codesize_minimal_O3.json index 08e058c9cd5ad..5fe4c0860fef6 100644 --- a/test/codesize/test_codesize_minimal_O3.json +++ b/test/codesize/test_codesize_minimal_O3.json @@ -1,10 +1,10 @@ { - "a.out.js": 2210, - "a.out.js.gz": 1089, + "a.out.js": 1998, + "a.out.js.gz": 1027, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 87, - "total": 2285, - "total_gz": 1176, + "total": 2073, + "total_gz": 1114, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_Os.json b/test/codesize/test_codesize_minimal_Os.json index 08e058c9cd5ad..5fe4c0860fef6 100644 --- a/test/codesize/test_codesize_minimal_Os.json +++ b/test/codesize/test_codesize_minimal_Os.json @@ -1,10 +1,10 @@ { - "a.out.js": 2210, - "a.out.js.gz": 1089, + "a.out.js": 1998, + "a.out.js.gz": 1027, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 87, - "total": 2285, - "total_gz": 1176, + "total": 2073, + "total_gz": 1114, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_Os_mr.json b/test/codesize/test_codesize_minimal_Os_mr.json index 2f947a492386e..f4b4c13a25bde 100644 --- a/test/codesize/test_codesize_minimal_Os_mr.json +++ b/test/codesize/test_codesize_minimal_Os_mr.json @@ -1,10 +1,10 @@ { - "a.out.js": 502, - "a.out.js.gz": 299, + "a.out.js": 278, + "a.out.js.gz": 225, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 87, - "total": 577, - "total_gz": 386, + "total": 353, + "total_gz": 312, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_Oz-ctors.json b/test/codesize/test_codesize_minimal_Oz-ctors.json index 1d23c0ca40143..01649ef200d36 100644 --- a/test/codesize/test_codesize_minimal_Oz-ctors.json +++ b/test/codesize/test_codesize_minimal_Oz-ctors.json @@ -1,10 +1,10 @@ { - "a.out.js": 2192, - "a.out.js.gz": 1077, + "a.out.js": 1980, + "a.out.js.gz": 1012, "a.out.nodebug.wasm": 64, "a.out.nodebug.wasm.gz": 80, - "total": 2256, - "total_gz": 1157, + "total": 2044, + "total_gz": 1092, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_Oz.json b/test/codesize/test_codesize_minimal_Oz.json index 08e058c9cd5ad..5fe4c0860fef6 100644 --- a/test/codesize/test_codesize_minimal_Oz.json +++ b/test/codesize/test_codesize_minimal_Oz.json @@ -1,10 +1,10 @@ { - "a.out.js": 2210, - "a.out.js.gz": 1089, + "a.out.js": 1998, + "a.out.js.gz": 1027, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 87, - "total": 2285, - "total_gz": 1176, + "total": 2073, + "total_gz": 1114, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_esm.json b/test/codesize/test_codesize_minimal_esm.json index eceee257497fd..fe01e4510c897 100644 --- a/test/codesize/test_codesize_minimal_esm.json +++ b/test/codesize/test_codesize_minimal_esm.json @@ -1,10 +1,10 @@ { - "a.out.js": 2348, - "a.out.js.gz": 1111, + "a.out.js": 2137, + "a.out.js.gz": 1050, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 87, - "total": 2423, - "total_gz": 1198, + "total": 2212, + "total_gz": 1137, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_pthreads.json b/test/codesize/test_codesize_minimal_pthreads.json index 6e1d93ed44b56..63dc7dfb19c00 100644 --- a/test/codesize/test_codesize_minimal_pthreads.json +++ b/test/codesize/test_codesize_minimal_pthreads.json @@ -1,10 +1,10 @@ { - "a.out.js": 6945, - "a.out.js.gz": 3424, + "a.out.js": 6849, + "a.out.js.gz": 3401, "a.out.nodebug.wasm": 19063, "a.out.nodebug.wasm.gz": 8803, - "total": 26008, - "total_gz": 12227, + "total": 25912, + "total_gz": 12204, "sent": [ "a (memory)", "b (exit)", diff --git a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json index a8cdb839d7f6d..255d27d1ee6ff 100644 --- a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json +++ b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json @@ -1,10 +1,10 @@ { - "a.out.js": 7379, - "a.out.js.gz": 3639, + "a.out.js": 7338, + "a.out.js.gz": 3628, "a.out.nodebug.wasm": 19064, "a.out.nodebug.wasm.gz": 8804, - "total": 26443, - "total_gz": 12443, + "total": 26402, + "total_gz": 12432, "sent": [ "a (memory)", "b (exit)", diff --git a/test/codesize/test_codesize_minimal_wasmfs.json b/test/codesize/test_codesize_minimal_wasmfs.json index 08e058c9cd5ad..5fe4c0860fef6 100644 --- a/test/codesize/test_codesize_minimal_wasmfs.json +++ b/test/codesize/test_codesize_minimal_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 2210, - "a.out.js.gz": 1089, + "a.out.js": 1998, + "a.out.js.gz": 1027, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 87, - "total": 2285, - "total_gz": 1176, + "total": 2073, + "total_gz": 1114, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_minimal_runtime_code_size_hello_embind.json b/test/codesize/test_minimal_runtime_code_size_hello_embind.json index d3f128deb07a6..7b9fa7b1daef4 100644 --- a/test/codesize/test_minimal_runtime_code_size_hello_embind.json +++ b/test/codesize/test_minimal_runtime_code_size_hello_embind.json @@ -2,9 +2,9 @@ "a.html": 548, "a.html.gz": 371, "a.js": 7249, - "a.js.gz": 3325, + "a.js.gz": 3322, "a.wasm": 7099, "a.wasm.gz": 3246, "total": 14896, - "total_gz": 6942 + "total_gz": 6939 } diff --git a/test/codesize/test_minimal_runtime_code_size_hello_embind_val.json b/test/codesize/test_minimal_runtime_code_size_hello_embind_val.json index f729802cdd1eb..9a1222bb13beb 100644 --- a/test/codesize/test_minimal_runtime_code_size_hello_embind_val.json +++ b/test/codesize/test_minimal_runtime_code_size_hello_embind_val.json @@ -2,9 +2,9 @@ "a.html": 548, "a.html.gz": 371, "a.js": 5346, - "a.js.gz": 2515, + "a.js.gz": 2516, "a.wasm": 5741, "a.wasm.gz": 2690, "total": 11635, - "total_gz": 5576 + "total_gz": 5577 } diff --git a/test/codesize/test_minimal_runtime_code_size_hello_wasm_worker.json b/test/codesize/test_minimal_runtime_code_size_hello_wasm_worker.json index b9e76134b7f12..9faf5f4e0f058 100644 --- a/test/codesize/test_minimal_runtime_code_size_hello_wasm_worker.json +++ b/test/codesize/test_minimal_runtime_code_size_hello_wasm_worker.json @@ -1,10 +1,10 @@ { "a.html": 515, "a.html.gz": 355, - "a.js": 945, - "a.js.gz": 593, + "a.js": 923, + "a.js.gz": 582, "a.wasm": 2661, "a.wasm.gz": 1479, - "total": 4121, - "total_gz": 2427 + "total": 4099, + "total_gz": 2416 } diff --git a/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm2js.json b/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm2js.json index 39c2e3644a679..9e0775c7bbb04 100644 --- a/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm2js.json +++ b/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm2js.json @@ -2,7 +2,7 @@ "a.html": 342, "a.html.gz": 252, "a.js": 18217, - "a.js.gz": 9828, + "a.js.gz": 9827, "total": 18559, - "total_gz": 10080 + "total_gz": 10079 } diff --git a/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm_singlefile.json b/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm_singlefile.json index b8bee5125d38e..1a8c46bd18e82 100644 --- a/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm_singlefile.json +++ b/test/codesize/test_minimal_runtime_code_size_hello_webgl2_wasm_singlefile.json @@ -1,4 +1,4 @@ { "a.html": 15040, - "a.html.gz": 9004 + "a.html.gz": 9027 } diff --git a/test/codesize/test_minimal_runtime_code_size_hello_webgl_wasm.json b/test/codesize/test_minimal_runtime_code_size_hello_webgl_wasm.json index ecb88a72d5678..318bc1fae19d2 100644 --- a/test/codesize/test_minimal_runtime_code_size_hello_webgl_wasm.json +++ b/test/codesize/test_minimal_runtime_code_size_hello_webgl_wasm.json @@ -2,9 +2,9 @@ "a.html": 450, "a.html.gz": 318, "a.js": 3961, - "a.js.gz": 2109, + "a.js.gz": 2108, "a.wasm": 8313, "a.wasm.gz": 5646, "total": 12724, - "total_gz": 8073 + "total_gz": 8072 } diff --git a/test/codesize/test_minimal_runtime_code_size_hello_world_wasm.json b/test/codesize/test_minimal_runtime_code_size_hello_world_wasm.json index 99c0d29ff9a53..d8132a0cf3154 100644 --- a/test/codesize/test_minimal_runtime_code_size_hello_world_wasm.json +++ b/test/codesize/test_minimal_runtime_code_size_hello_world_wasm.json @@ -2,9 +2,9 @@ "a.html": 548, "a.html.gz": 371, "a.js": 284, - "a.js.gz": 240, + "a.js.gz": 239, "a.wasm": 95, "a.wasm.gz": 101, "total": 927, - "total_gz": 712 + "total_gz": 711 } diff --git a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json index 206b2029eedff..98f3f3999840a 100644 --- a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json +++ b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json @@ -1,4 +1,4 @@ { "a.html": 11054, - "a.html.gz": 5754 + "a.html.gz": 5752 } diff --git a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json index 5dc96cb01d779..269bfba988fe7 100644 --- a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json +++ b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json @@ -1,4 +1,4 @@ { "a.html": 17417, - "a.html.gz": 7658 + "a.html.gz": 7659 } diff --git a/test/codesize/test_small_js_flags.expected.js b/test/codesize/test_small_js_flags.expected.js index 270f694ffdc4c..fa215b7d49a5b 100644 --- a/test/codesize/test_small_js_flags.expected.js +++ b/test/codesize/test_small_js_flags.expected.js @@ -107,16 +107,8 @@ var runtimeInitialized = false; function updateMemoryViews() { var b = wasmMemory.buffer; - HEAP8 = new Int8Array(b); - HEAP16 = new Int16Array(b); HEAPU8 = new Uint8Array(b); - HEAPU16 = new Uint16Array(b); - HEAP32 = new Int32Array(b); HEAPU32 = new Uint32Array(b); - HEAPF32 = new Float32Array(b); - HEAPF64 = new Float64Array(b); - HEAP64 = new BigInt64Array(b); - HEAPU64 = new BigUint64Array(b); } // include: memoryprofiler.js @@ -262,26 +254,6 @@ class ExitStatus { } } -/** @type {!Int16Array} */ var HEAP16; - -/** @type {!Int32Array} */ var HEAP32; - -/** not-@type {!BigInt64Array} */ var HEAP64; - -/** @type {!Int8Array} */ var HEAP8; - -/** @type {!Float32Array} */ var HEAPF32; - -/** @type {!Float64Array} */ var HEAPF64; - -/** @type {!Uint16Array} */ var HEAPU16; - -/** @type {!Uint32Array} */ var HEAPU32; - -/** not-@type {!BigUint64Array} */ var HEAPU64; - -/** @type {!Uint8Array} */ var HEAPU8; - var printCharBuffers = [ null, [], [] ]; var UTF8Decoder = globalThis.TextDecoder && new TextDecoder; @@ -360,6 +332,10 @@ var printChar = (stream, curr) => { } }; +/** @type {!Uint8Array} */ var HEAPU8; + +/** @type {!Uint32Array} */ var HEAPU32; + var _fd_write = (fd, iov, iovcnt, pnum) => { // hack to support printf in SYSCALLS_REQUIRE_FILESYSTEM=0 var num = 0; diff --git a/test/codesize/test_small_js_flags.json b/test/codesize/test_small_js_flags.json index 7ca0c00f0cfbd..fca4a53fc1243 100644 --- a/test/codesize/test_small_js_flags.json +++ b/test/codesize/test_small_js_flags.json @@ -1,10 +1,10 @@ { - "a.out.js": 2222, - "a.out.js.gz": 1230, + "a.out.js": 2066, + "a.out.js.gz": 1187, "a.out.nodebug.wasm": 1666, "a.out.nodebug.wasm.gz": 945, - "total": 3888, - "total_gz": 2175, + "total": 3732, + "total_gz": 2132, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_unoptimized_code_size.json b/test/codesize/test_unoptimized_code_size.json index 5e254e55d89b8..38c3216fcc42a 100644 --- a/test/codesize/test_unoptimized_code_size.json +++ b/test/codesize/test_unoptimized_code_size.json @@ -1,16 +1,16 @@ { - "hello_world.js": 56153, - "hello_world.js.gz": 17678, + "hello_world.js": 54379, + "hello_world.js.gz": 17284, "hello_world.wasm": 15115, "hello_world.wasm.gz": 7464, - "no_asserts.js": 25585, - "no_asserts.js.gz": 8688, + "no_asserts.js": 23708, + "no_asserts.js.gz": 8297, "no_asserts.wasm": 12229, "no_asserts.wasm.gz": 6004, - "strict.js": 53255, - "strict.js.gz": 16649, + "strict.js": 51481, + "strict.js.gz": 16276, "strict.wasm": 15115, "strict.wasm.gz": 7461, - "total": 177452, - "total_gz": 63944 + "total": 172027, + "total_gz": 62786 } From f767cb7d4c7e4b80f37efaa8fea38b3d063cf7ca Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Tue, 7 Jul 2026 23:21:41 +0000 Subject: [PATCH 3/6] docs --- src/settings.js | 4 ---- src/settings_internal.js | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/settings.js b/src/settings.js index 063bbe353a417..24c88a7be4749 100644 --- a/src/settings.js +++ b/src/settings.js @@ -2335,7 +2335,3 @@ var FAKE_DYLIBS = false; // This setting can also be set to a string value, in which case that string // will be used as the #! command to embed in the generated file. var EXECUTABLE = false; - -// Internal setting for passing EM_JS and EM_ASM function code snippets to JSifier. -// [internal] -var EM_JS_SNIPPETS = []; diff --git a/src/settings_internal.js b/src/settings_internal.js index 3b425fccba8bf..9d5da03a64fc1 100644 --- a/src/settings_internal.js +++ b/src/settings_internal.js @@ -295,5 +295,8 @@ var LOAD_SOURCE_MAP = false; var ALIASES = []; +// Internal setting for passing EM_JS and EM_ASM function code snippets to JSifier. +var EM_JS_SNIPPETS = []; + // List of public setting names (Used by RETAIN_COMPILER_SETTINGS) var PUBLIC_SETTINGS = []; From 646db88dcf67df205c698d4b26ce96c7272dd96c Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Thu, 9 Jul 2026 23:41:33 +0000 Subject: [PATCH 4/6] review comments --- src/jsifier.mjs | 11 ++++++++++- src/runtime_common.js | 10 +++++----- src/settings_internal.js | 5 ++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/jsifier.mjs b/src/jsifier.mjs index 5afef3b32fcda..657d41b1c3e63 100644 --- a/src/jsifier.mjs +++ b/src/jsifier.mjs @@ -255,6 +255,9 @@ function addImplicitDeps(snippet, deps) { deps.push('$' + dep); } } + // If the snippet contains eval(), it may dynamically evaluate strings that reference any + // heap view (e.g., eval('HEAP8[0]')). Since static string matching cannot detect which + // heap views are used inside dynamically evaluated code, we must include all of them. if (snippet.includes('eval(')) { deps.push('$HEAP8', '$HEAPU8', '$HEAP16', '$HEAPU16', '$HEAP32', '$HEAPU32', '$HEAPF32', '$HEAPF64'); if (WASM_BIGINT || MEMORY64) { @@ -309,8 +312,14 @@ function getRequiredHeapSymbols() { heaps.add('$HEAP64').add('$HEAPU64'); } } + // runtime_common.js accesses HEAP8 under ALLOW_MEMORY_GROWTH (to check buffer resizability), + // RUNTIME_DEBUG (to log initial setup), and ASSERTIONS (to guard against re-entrancy when + // ALLOW_MEMORY_GROWTH is 0). + if (ALLOW_MEMORY_GROWTH || RUNTIME_DEBUG || ASSERTIONS) { + heaps.add('$HEAP8'); + } } - return Array.from(heaps); + return heaps; } function sigToArgs(sig) { diff --git a/src/runtime_common.js b/src/runtime_common.js index 6ba365317e492..6eee4e9d9dc60 100644 --- a/src/runtime_common.js +++ b/src/runtime_common.js @@ -17,7 +17,7 @@ // must be updated. function growMemViews() { // `updateMemoryViews` updates all the views simultaneously, so it's enough to check any of them. - if (typeof HEAP8 != 'undefined' && wasmMemory.buffer != HEAP8.buffer) { + if (wasmMemory.buffer != HEAP8.buffer) { updateMemoryViews(); } } @@ -152,21 +152,21 @@ function getMemoryBuffer() { function updateMemoryViews() { #if RUNTIME_DEBUG - dbg(`updateMemoryViews: first=${typeof HEAP8 == 'undefined' || !HEAP8} size=${wasmMemory.buffer.byteLength}`); + dbg(`updateMemoryViews: first=${!HEAP8} size=${wasmMemory.buffer.byteLength}`); #endif #if ALLOW_MEMORY_GROWTH // If we already have a heap that is resizeable/growable buffer we don't // need to do anything in updateMemoryViews. #if SHARED_MEMORY - if (typeof HEAP8 != 'undefined' && HEAP8?.buffer?.growable) return; + if (HEAP8?.buffer?.growable) return; #else - if (typeof HEAP8 != 'undefined' && HEAP8?.buffer?.resizable) return; + if (HEAP8?.buffer?.resizable) return; #endif var b = getMemoryBuffer(); #else #if ASSERTIONS // When memory growth is disabled this function should be called exactly once. - assert(typeof HEAP8 == 'undefined' || !HEAP8, 'updateMemoryViews should only be called once when ALLOW_MEMORY_GROWTH=0'); + assert(!HEAP8, 'updateMemoryViews should only be called once when ALLOW_MEMORY_GROWTH=0'); #endif var b = wasmMemory.buffer; #endif diff --git a/src/settings_internal.js b/src/settings_internal.js index 9d5da03a64fc1..7405b50118136 100644 --- a/src/settings_internal.js +++ b/src/settings_internal.js @@ -295,7 +295,10 @@ var LOAD_SOURCE_MAP = false; var ALIASES = []; -// Internal setting for passing EM_JS and EM_ASM function code snippets to JSifier. +// Internal setting for passing EM_JS and EM_ASM function code snippets to JSifier so that +// implicit heap dependencies (e.g. HEAP8, HEAP32) can be scanned and included automatically +// without needing to search for them in Python. +// This could be removed if/when we require explicit heap dependencies (via EM_JS_DEPS). var EM_JS_SNIPPETS = []; // List of public setting names (Used by RETAIN_COMPILER_SETTINGS) From a65bcda8dc7db417d8581a8234f0107a3a318457 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Fri, 10 Jul 2026 00:01:23 +0000 Subject: [PATCH 5/6] review comments --- src/jsifier.mjs | 8 +++++--- tools/emscripten.py | 2 +- tools/link.py | 4 +--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/jsifier.mjs b/src/jsifier.mjs index 657d41b1c3e63..ca9b1564ab517 100644 --- a/src/jsifier.mjs +++ b/src/jsifier.mjs @@ -247,6 +247,7 @@ function addImplicitDeps(snippet, deps) { 'runtimeKeepalivePush', 'runtimeKeepalivePop', 'UTF8ToString', + // TODO: Consider removing getValue and setValue if they are rarely used implicitly. 'getValue', 'setValue', ]; @@ -255,9 +256,10 @@ function addImplicitDeps(snippet, deps) { deps.push('$' + dep); } } - // If the snippet contains eval(), it may dynamically evaluate strings that reference any - // heap view (e.g., eval('HEAP8[0]')). Since static string matching cannot detect which - // heap views are used inside dynamically evaluated code, we must include all of them. + // If the snippet contains eval(), it may dynamically evaluate code loaded from memory at runtime + // (for example, in emscripten_run_script where the snippet is eval(UTF8ToString(ptr))). + // Because static string matching cannot inspect what strings are stored in memory or evaluated + // at runtime, we must conservatively include all heap views whenever a snippet uses eval(). if (snippet.includes('eval(')) { deps.push('$HEAP8', '$HEAPU8', '$HEAP16', '$HEAPU16', '$HEAP32', '$HEAPU32', '$HEAPF32', '$HEAPF64'); if (WASM_BIGINT || MEMORY64) { diff --git a/tools/emscripten.py b/tools/emscripten.py index 4c3dd367b56f1..a4c0a491af011 100644 --- a/tools/emscripten.py +++ b/tools/emscripten.py @@ -390,7 +390,7 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True, base_metadat asm_consts = create_asm_consts(metadata) em_js_funcs = create_em_js(metadata) - settings.EM_JS_SNIPPETS = em_js_funcs + [f for _, f in asm_consts] + settings.EM_JS_SNIPPETS = em_js_funcs + [f[1] for f in asm_consts] if settings.SIDE_MODULE: # When building side modules, validate the EM_ASM and EM_JS string by running diff --git a/tools/link.py b/tools/link.py index d336c4d82eae2..5101814e68950 100644 --- a/tools/link.py +++ b/tools/link.py @@ -1194,9 +1194,7 @@ def limit_incoming_module_api(): if prop not in settings.ALL_INCOMING_MODULE_JS_API: diagnostics.warning('unused-command-line-argument', f'invalid entry in INCOMING_MODULE_JS_API: {prop}') - settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += [ - '$wasmMemory', - ] + settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$wasmMemory'] if 'noExitRuntime' in settings.INCOMING_MODULE_JS_API: settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.append('$noExitRuntime') From f8e2d97678e7d2f900bcff28e918abf6b56bd507 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Fri, 10 Jul 2026 19:55:09 +0000 Subject: [PATCH 6/6] move to python --- src/jsifier.mjs | 47 --------------------------------------------- tools/emscripten.py | 3 +++ tools/link.py | 44 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/jsifier.mjs b/src/jsifier.mjs index ca9b1564ab517..de51b0d6fd992 100644 --- a/src/jsifier.mjs +++ b/src/jsifier.mjs @@ -278,52 +278,6 @@ function addImplicitDeps(snippet, deps) { } } -// Auto-include heap views and helper symbols required by certain build modes or runtime -// scaffolding files (e.g., postamble.js, runtime_stack_check.js, memoryprofiler.js). -// Because addImplicitDeps only scans library functions and user code (pre-js/post-js/EM_JS), -// runtime scaffolding files that access linear memory directly must have their heap views -// explicitly declared here so they are emitted in the final JS bundle. -function getRequiredHeapSymbols() { - const heaps = new Set(); - if (MAIN_MODULE || EXPORT_ALL || SAFE_HEAP) { - // Dynamic linking side modules, full symbol exports, or safe heap instrumentation - // require all standard heap views and value helpers to be available. - heaps.add('$getValue').add('$setValue'); - heaps.add('$HEAP8').add('$HEAPU8').add('$HEAP16').add('$HEAPU16') - .add('$HEAP32').add('$HEAPU32').add('$HEAPF32').add('$HEAPF64'); - if (WASM_BIGINT || MEMORY64) { - heaps.add('$HEAP64').add('$HEAPU64'); - } - } else { - // STACK_OVERFLOW_CHECK accesses HEAP32/HEAPU32 in runtime_stack_check.js. - // MAIN_READS_PARAMS populates argv pointers in linear memory in postamble.js (callMain). - if (STACK_OVERFLOW_CHECK || (HAS_MAIN && MAIN_READS_PARAMS)) { - heaps.add('$HEAP32').add('$HEAPU32'); - if ((HAS_MAIN && MAIN_READS_PARAMS) && (WASM_BIGINT || MEMORY64)) { - heaps.add('$HEAP64').add('$HEAPU64'); - } - } - // MEMORYPROFILER accesses HEAP8 in memoryprofiler.js. - if (MEMORYPROFILER) { - heaps.add('$HEAP8'); - } - // AUDIO_WORKLET accesses HEAP32, HEAPU32, and HEAPF32 in audio_worklet.js. - if (AUDIO_WORKLET) { - heaps.add('$HEAP32').add('$HEAPU32').add('$HEAPF32'); - if (WASM_BIGINT || MEMORY64) { - heaps.add('$HEAP64').add('$HEAPU64'); - } - } - // runtime_common.js accesses HEAP8 under ALLOW_MEMORY_GROWTH (to check buffer resizability), - // RUNTIME_DEBUG (to log initial setup), and ASSERTIONS (to guard against re-entrancy when - // ALLOW_MEMORY_GROWTH is 0). - if (ALLOW_MEMORY_GROWTH || RUNTIME_DEBUG || ASSERTIONS) { - heaps.add('$HEAP8'); - } - } - return heaps; -} - function sigToArgs(sig) { const args = [] for (var i = 1; i < sig.length; i++) { @@ -477,7 +431,6 @@ export async function runJSify(outputFile, symbolsOnly) { const symbolsNeeded = DEFAULT_LIBRARY_FUNCS_TO_INCLUDE; symbolsNeeded.push(...extraLibraryFuncs); - symbolsNeeded.push(...getRequiredHeapSymbols()); for (const fileName of [...PRE_JS_FILES, ...POST_JS_FILES]) { const content = readFile(fileName); diff --git a/tools/emscripten.py b/tools/emscripten.py index a4c0a491af011..4785aa1e86dc7 100644 --- a/tools/emscripten.py +++ b/tools/emscripten.py @@ -30,6 +30,7 @@ extract_metadata, filelock, js_manipulation, + link, shared, utils, webassembly, @@ -155,6 +156,8 @@ def update_settings_glue(wasm_file, metadata, base_metadata): for deps in metadata.js_deps: settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.extend(deps.split(',')) + link.add_required_heap_symbols() + def apply_static_code_hooks(forwarded_json, code): def inject_code_hooks(name): diff --git a/tools/link.py b/tools/link.py index 5101814e68950..4daf89a08b19b 100644 --- a/tools/link.py +++ b/tools/link.py @@ -806,6 +806,49 @@ def setup_cross_origin_storage(): exit_with_error(f"CROSS_ORIGIN_STORAGE_ORIGINS: {o!r} is not a valid HTTPS origin (expected 'https://host' or 'https://host:port')") +def add_required_heap_symbols(): + """Auto-include heap views and helper symbols required by certain build modes or runtime. + + Because addImplicitDeps only scans library functions and user code (pre-js/post-js/EM_JS), + runtime scaffolding files (e.g., postamble.js, runtime_stack_check.js, memoryprofiler.js) + that access linear memory directly must have their heap views explicitly declared here + so they are emitted in the final JS bundle. + """ + heaps = [] + if settings.MAIN_MODULE or settings.EXPORT_ALL or settings.SAFE_HEAP: + # Dynamic linking side modules, full symbol exports, or safe heap instrumentation + # require all standard heap views and value helpers to be available. + heaps += ['$getValue', '$setValue'] + heaps += ['$HEAP8', '$HEAPU8', '$HEAP16', '$HEAPU16', + '$HEAP32', '$HEAPU32', '$HEAPF32', '$HEAPF64'] + if settings.WASM_BIGINT or settings.MEMORY64: + heaps += ['$HEAP64', '$HEAPU64'] + else: + # STACK_OVERFLOW_CHECK accesses HEAP32/HEAPU32 in runtime_stack_check.js. + # MAIN_READS_PARAMS populates argv pointers in linear memory in postamble.js (callMain). + if settings.STACK_OVERFLOW_CHECK or (settings.HAS_MAIN and settings.MAIN_READS_PARAMS): + heaps += ['$HEAP32', '$HEAPU32'] + if (settings.HAS_MAIN and settings.MAIN_READS_PARAMS) and (settings.WASM_BIGINT or settings.MEMORY64): + heaps += ['$HEAP64', '$HEAPU64'] + # MEMORYPROFILER accesses HEAP8 in memoryprofiler.js. + if settings.MEMORYPROFILER: + heaps.append('$HEAP8') + # AUDIO_WORKLET accesses HEAP32, HEAPU32, and HEAPF32 in audio_worklet.js. + if settings.AUDIO_WORKLET: + heaps += ['$HEAP32', '$HEAPU32', '$HEAPF32'] + if settings.WASM_BIGINT or settings.MEMORY64: + heaps += ['$HEAP64', '$HEAPU64'] + # runtime_common.js accesses HEAP8 under ALLOW_MEMORY_GROWTH (to check buffer resizability), + # RUNTIME_DEBUG (to log initial setup), and ASSERTIONS (to guard against re-entrancy when + # ALLOW_MEMORY_GROWTH is 0). + if settings.ALLOW_MEMORY_GROWTH or settings.RUNTIME_DEBUG or settings.ASSERTIONS: + heaps.append('$HEAP8') + + for h in heaps: + if h not in settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE: + settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.append(h) + + @ToolchainProfiler.profile_block('linker_setup') def phase_linker_setup(options, linker_args): # noqa: C901, PLR0912, PLR0915 """Future modifications should consider refactoring to reduce complexity. @@ -1848,6 +1891,7 @@ def get_full_import_name(name): if settings.USE_CLOSURE_COMPILER or not settings.MINIFY_WHITESPACE: settings.MAYBE_CLOSURE_COMPILER = 1 + add_required_heap_symbols() check_settings() return target, wasm_target