From e49267382b194a6983ce49bf18f421cfb75b56a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Fri, 16 Jan 2026 09:27:54 +0200 Subject: [PATCH 1/2] When building -sSINGLE_FILE builds with -sSINGLE_FILE_BINARY_ENCODE enabled, the base64Decode function was being emitted, and Closure was unable to DCE away the dependent base64ReverseLookup variable. So optimize this away manually to save code size. --- src/lib/libbase64.js | 10 ++++++---- tools/link.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/libbase64.js b/src/lib/libbase64.js index 48546622878f1..3f0739e9d155c 100644 --- a/src/lib/libbase64.js +++ b/src/lib/libbase64.js @@ -8,18 +8,20 @@ addToLibrary({ // Decodes a _known valid_ base64 string (without validation) and returns it as a new Uint8Array. // Benchmarked to be around 5x faster compared to a simple // "Uint8Array.from(atob(b64), c => c.charCodeAt(0))" (TODO: perhaps use this form in -Oz builds?) +#if !JS_BASE64_API $base64Decode__postset: ` // Precreate a reverse lookup table from chars // "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" back to // bytes to make decoding fast. - for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), i = 25; i >= 0; --i) { - base64ReverseLookup[48+i] = 52+i; // '0-9' - base64ReverseLookup[65+i] = i; // 'A-Z' - base64ReverseLookup[97+i] = 26+i; // 'a-z' + for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), __b64i = 25; __b64i >= 0; --__b64i) { + base64ReverseLookup[48+__b64i] = 52+__b64i; // '0-9' + base64ReverseLookup[65+__b64i] = __b64i; // 'A-Z' + base64ReverseLookup[97+__b64i] = 26+__b64i; // 'a-z' } base64ReverseLookup[43] = 62; // '+' base64ReverseLookup[47] = 63; // '/' `, +#endif $base64Decode__docs: '/** @noinline */', $base64Decode: (b64) => { #if JS_BASE64_API diff --git a/tools/link.py b/tools/link.py index 4303f257ea9dc..54f44551cfed7 100644 --- a/tools/link.py +++ b/tools/link.py @@ -1957,7 +1957,7 @@ def phase_emscript(in_wasm, wasm_target, js_syms, base_metadata): # No need to support base64 embedding in wasm2js mode since # the module is already in JS format. - if settings.SINGLE_FILE and not settings.WASM2JS: + if settings.SINGLE_FILE and not settings.SINGLE_FILE_BINARY_ENCODE and not settings.WASM2JS: settings.SUPPORT_BASE64_EMBEDDING = 1 settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.append('$base64Decode') From f634570437631d524068ac0a2470740451145584 Mon Sep 17 00:00:00 2001 From: juj Date: Thu, 26 Feb 2026 23:33:54 +0200 Subject: [PATCH 2/2] Automatic rebaseline of codesize expectations. NFC This is an automatic change generated by tools/maint/rebaseline_tests.py. The following (3) test expectation files were updated by running the tests with `--rebaseline`: ``` codesize/test_codesize_hello_single_file.json: 5371 => 5273 [-98 bytes / -1.82%] codesize/test_minimal_runtime_code_size_hello_webgl2_wasm_singlefile.json: 15140 => 15046 [-94 bytes / -0.62%] codesize/test_minimal_runtime_code_size_random_printf_wasm.json: 10982 => 10884 [-98 bytes / -0.89%] Average change: -1.11% (-1.82% - -0.62%) ``` --- test/codesize/test_codesize_hello_single_file.json | 4 ++-- ...inimal_runtime_code_size_hello_webgl2_wasm_singlefile.json | 4 ++-- .../test_minimal_runtime_code_size_random_printf_wasm.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/codesize/test_codesize_hello_single_file.json b/test/codesize/test_codesize_hello_single_file.json index 531826ef78b44..44dea2cde8813 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": 5371, - "a.out.js.gz": 2984, + "a.out.js": 5273, + "a.out.js.gz": 2921, "sent": [ "a (fd_write)" ] 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 819c402815ee8..3d2402f8aff1b 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": 15140, - "a.html.gz": 9079 + "a.html": 15046, + "a.html.gz": 9018 } 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 61f7f42ba4aff..41ce4cfdd5704 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": 10982, - "a.html.gz": 5743 + "a.html": 10884, + "a.html.gz": 5674 }