From 50d85749763b4c820a0c0b50ed99070f7035fc58 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] 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 | 2 ++ tools/link.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/libbase64.js b/src/lib/libbase64.js index 48546622878f1..4aec0a54aa2a5 100644 --- a/src/lib/libbase64.js +++ b/src/lib/libbase64.js @@ -8,6 +8,7 @@ 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 @@ -20,6 +21,7 @@ addToLibrary({ 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 08e7d05f372fe..e2b290ab34d8f 100644 --- a/tools/link.py +++ b/tools/link.py @@ -1969,7 +1969,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')