From 8b3f8008b901fc8c6b2f102aef3074e545341e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Tue, 23 Sep 2025 03:13:43 +0300 Subject: [PATCH 1/3] Optimize ENVIRONMENT_IS_WASM_WORKER check when building with Audio Worklets enabled, for a code size saving of 7 bytes. --- src/shell_minimal.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/shell_minimal.js b/src/shell_minimal.js index a2f5017210a7f..1e0a6d82ebcf7 100644 --- a/src/shell_minimal.js +++ b/src/shell_minimal.js @@ -63,22 +63,23 @@ if (ENVIRONMENT_IS_NODE) { } #endif -#if WASM_WORKERS +#if AUDIO_WORKLET +var ENVIRONMENT_IS_AUDIO_WORKLET = typeof AudioWorkletGlobalScope !== 'undefined'; +#endif + +#if AUDIO_WORKLET && WASM_WORKERS +var ENVIRONMENT_IS_WASM_WORKER = globalThis.name == 'em-ww' || ENVIRONMENT_IS_AUDIO_WORKLET; +#elif WASM_WORKERS var ENVIRONMENT_IS_WASM_WORKER = globalThis.name == 'em-ww'; +#endif -#if ENVIRONMENT_MAY_BE_NODE +#if WASM_WORKERS && ENVIRONMENT_MAY_BE_NODE if (ENVIRONMENT_IS_NODE) { // The way we signal to a worker that it is hosting a pthread is to construct // it with a specific name. ENVIRONMENT_IS_WASM_WORKER = worker_threads['workerData'] == 'em-ww' } #endif -#endif - -#if AUDIO_WORKLET -var ENVIRONMENT_IS_AUDIO_WORKLET = typeof AudioWorkletGlobalScope !== 'undefined'; -if (ENVIRONMENT_IS_AUDIO_WORKLET) ENVIRONMENT_IS_WASM_WORKER = true; -#endif #if ASSERTIONS && ENVIRONMENT_MAY_BE_NODE && ENVIRONMENT_MAY_BE_SHELL if (ENVIRONMENT_IS_NODE && ENVIRONMENT_IS_SHELL) { From 85bbf246d32d03778bb912da9f68a0db6a196c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Thu, 25 Sep 2025 23:24:22 +0300 Subject: [PATCH 2/3] Merge --- src/shell_minimal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shell_minimal.js b/src/shell_minimal.js index 1e0a6d82ebcf7..e8c8ead12daf0 100644 --- a/src/shell_minimal.js +++ b/src/shell_minimal.js @@ -64,7 +64,7 @@ if (ENVIRONMENT_IS_NODE) { #endif #if AUDIO_WORKLET -var ENVIRONMENT_IS_AUDIO_WORKLET = typeof AudioWorkletGlobalScope !== 'undefined'; +var ENVIRONMENT_IS_AUDIO_WORKLET = !!globalThis.AudioWorkletGlobalScope; #endif #if AUDIO_WORKLET && WASM_WORKERS From 44564fdb89a6ff36fbfafef975ce9ad825da2c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Thu, 25 Sep 2025 23:26:04 +0300 Subject: [PATCH 3/3] Code size --- test/codesize/audio_worklet_wasm.js | 16 +++++++--------- ..._minimal_runtime_code_size_audio_worklet.json | 8 ++++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/test/codesize/audio_worklet_wasm.js b/test/codesize/audio_worklet_wasm.js index abfd8c6aa79e6..8e566511b9b11 100644 --- a/test/codesize/audio_worklet_wasm.js +++ b/test/codesize/audio_worklet_wasm.js @@ -1,6 +1,4 @@ -var m = globalThis.Module || "undefined" != typeof Module ? Module : {}, q = "em-ww" == globalThis.name, r = !!globalThis.AudioWorkletGlobalScope, t, z, J, K, H, E, v, X, F, D, C, Y, A, Z; - -r && (q = !0); +var m = globalThis.Module || "undefined" != typeof Module ? Module : {}, q = !!globalThis.AudioWorkletGlobalScope, r = "em-ww" == globalThis.name || q, t, z, J, K, H, E, v, X, F, D, C, Y, A, Z; function u(a) { t = a; @@ -12,12 +10,12 @@ function u(a) { a.G = a.M = 0; } -q && !r && (onmessage = a => { +r && !q && (onmessage = a => { onmessage = null; u(a.data); }); -if (r) { +if (q) { function a(c) { class e extends AudioWorkletProcessor { constructor(d) { @@ -98,7 +96,7 @@ function w() { E = new Float32Array(a); } -q || (v = m.mem || new WebAssembly.Memory({ +r || (v = m.mem || new WebAssembly.Memory({ initial: 256, maximum: 256, shared: !0 @@ -236,9 +234,9 @@ function y() { C = a.n; Y = a.o; A = a.k; - q ? (Y(t.J, t.F), r || (removeEventListener("message", N), L = L.forEach(M), addEventListener("message", M))) : a.i(); - q || X(); + r ? (Y(t.J, t.F), q || (removeEventListener("message", N), L = L.forEach(M), addEventListener("message", M))) : a.i(); + r || X(); })); } -q || y(); \ No newline at end of file +r || y(); \ No newline at end of file diff --git a/test/codesize/test_minimal_runtime_code_size_audio_worklet.json b/test/codesize/test_minimal_runtime_code_size_audio_worklet.json index 7e8c0818c0cd3..924ddf6c0e295 100644 --- a/test/codesize/test_minimal_runtime_code_size_audio_worklet.json +++ b/test/codesize/test_minimal_runtime_code_size_audio_worklet.json @@ -1,10 +1,10 @@ { "a.html": 519, "a.html.gz": 357, - "a.js": 3928, - "a.js.gz": 2074, + "a.js": 3921, + "a.js.gz": 2069, "a.wasm": 1308, "a.wasm.gz": 876, - "total": 5755, - "total_gz": 3307 + "total": 5748, + "total_gz": 3302 }