commit f08d2c86a02b8a7b564577cc392af790ef43639c
parent f168b2aebd4fbf26e41ecb1a4e1430dffa3a4ac1
Author: anon <anon@example.com>
Date: Sun, 18 Oct 2026 08:01:29 +0000
Optimize browser guest calls with ThinLTO
Diffstat:
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
@@ -84,6 +84,8 @@ make wasm -j8
This downloads/builds the audio dependencies, compiles the game, and writes the
six files above to ignored `client/`, where Go serves them. The first build is
heavy; allow several gigabytes of build space and substantial compilation time.
+ThinLTO optimizes calls across source files with eight linker workers. Keep
+`src/build/wasm/lto-cache/` to reuse that work on subsequent builds.
Copy the complete matching bundle to other machines after validating it. Do not
mix JavaScript and WASM from different builds or commit generated client files.
diff --git a/src/Makefile.wasm b/src/Makefile.wasm
@@ -1,7 +1,7 @@
CC := ../toolchains/emsdk/upstream/emscripten/emcc
CPPFLAGS := -Iruntime -Igame -Idata -DRECOMP_PORTABLE
# Keep exception landing pads in Wasm so JSPI can yield through guest calls.
-CFLAGS := -O2 -fno-strict-aliasing -pthread -sSUPPORT_LONGJMP=wasm
+CFLAGS := -O2 -flto=thin -fno-strict-aliasing -pthread -sSUPPORT_LONGJMP=wasm
PORT_FLAGS := -sUSE_SDL=2 -sUSE_FREETYPE=1
RUNTIME_SOURCES := runtime/linux_host.c runtime/linux_imports.c runtime/linux_gdi.c runtime/linux_audio.c runtime/linux_music.c runtime/browser_audio.c runtime/linux_window.c runtime/linux_graphics.c runtime/gl_renderer.c runtime/linux_platform.c runtime/linux_diagnostics.c runtime/linux_sync.c runtime/linux_file.c runtime/linux_tls.c runtime/linux_thread.c runtime/linux_snapshot.c runtime/browser_network.c runtime/guest_memory.c runtime/guest_heap.c runtime/guest_crt.c runtime/guest_stdio.c runtime/guest_exception.c runtime/guest_rtti.c runtime/guest_format.c runtime/guest_msvcp.c runtime/recomp_state.c runtime/eh32.c runtime/linux_path.c runtime/browser_host.c runtime/browser_resolution.c runtime/browser_profile.c
GAME_SOURCES := $(wildcard game/*/*.c) game/dispatch.c
@@ -12,6 +12,9 @@ OBJECTS := $(patsubst %.c,build/wasm/objects/%.o,$(GAME_SOURCES) $(DATA_SOURCES)
.DEFAULT_GOAL := all
include Makefile.portable
+# Compiler flag changes must rebuild objects as well as relink the client.
+$(OBJECTS): Makefile.wasm
+
build/wasm/resolved-calls.js: build/portable/tests/resolved_calls.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h
@mkdir -p $(@D)
$(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) -o $@
@@ -49,7 +52,7 @@ build/wasm/web/devices-test.html: tests/devices.c runtime/linux_graphics.c runti
build/wasm/web/game.js build/wasm/web/game.wasm &: $(OBJECTS) runtime/browser_network.js runtime/browser_host.js runtime/browser_fetch.js runtime/browser_audio.js runtime/browser_profile.js ../local/wasm/deps/lib/libsndfile.a ../local/wasm/deps/lib/libmp3lame.a Makefile.wasm
@mkdir -p $(@D)
- $(CC) $(CFLAGS) $(PORT_FLAGS) $(OBJECTS) ../local/wasm/deps/lib/libsndfile.a ../local/wasm/deps/lib/libmp3lame.a -sUSE_MPG123=1 -sWASMFS -sPROXY_TO_PTHREAD -sPTHREAD_POOL_SIZE=8 -sALLOW_BLOCKING_ON_MAIN_THREAD=0 -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -sOFFSCREENCANVAS_SUPPORT -sJSPI -sALLOW_MEMORY_GROWTH -sINITIAL_MEMORY=268435456 -sSTACK_SIZE=8388608 --js-library runtime/browser_network.js --js-library runtime/browser_host.js --js-library runtime/browser_fetch.js --js-library runtime/browser_audio.js --js-library runtime/browser_profile.js -sBINARYEN_EXTRA_PASSES=merge-similar-functions --emit-symbol-map -o build/wasm/web/game.js
+ $(CC) $(CFLAGS) $(PORT_FLAGS) $(OBJECTS) ../local/wasm/deps/lib/libsndfile.a ../local/wasm/deps/lib/libmp3lame.a -sUSE_MPG123=1 -sWASMFS -sPROXY_TO_PTHREAD -sPTHREAD_POOL_SIZE=8 -sALLOW_BLOCKING_ON_MAIN_THREAD=0 -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -sOFFSCREENCANVAS_SUPPORT -sJSPI -sALLOW_MEMORY_GROWTH -sINITIAL_MEMORY=268435456 -sSTACK_SIZE=8388608 --js-library runtime/browser_network.js --js-library runtime/browser_host.js --js-library runtime/browser_fetch.js --js-library runtime/browser_audio.js --js-library runtime/browser_profile.js -sBINARYEN_EXTRA_PASSES=merge-similar-functions -Wl,--thinlto-jobs=8 -Wl,--thinlto-cache-dir=build/wasm/lto-cache --emit-symbol-map -o build/wasm/web/game.js
build/wasm/web/index.html: browser/index.html
@mkdir -p $(@D)