The Problem with WebAssembly Payloads

When porting a desktop game to the web using Godot 4, the initial WebAssembly (WASM) payload can easily exceed 20MB. For a web portal or an online portfolio, asking users to wait for a 20MB download is often a conversion killer. In this article, we explore the aggressive optimization techniques used to bring the payload size of Modern Tetris down to a manageable size.

Step 1: Stripping the Engine Modules

Godot's default export templates contain everything from 3D physics engines (Bullet) to AR/VR support. By compiling a custom export template using a tailored custom.py configuration file, we can strip out modules that a 2D puzzle game absolutely does not need.

For example, disabling module_3d_enabled=no, module_webrtc_enabled=no, and module_csg_enabled=no immediately shaved off 40% of the binary size.

Step 2: Asset Compression Strategies

Textures are the next largest memory hog. While VRAM compression (S3TC, BPTC) is essential for desktop GPUs, VRAM-compressed formats often compress poorly over the wire compared to standard formats. By experimenting with WebP lossless compression and keeping power-of-two texture bounds strict, we achieved a balance between visual fidelity and download speed.

Audio is equally problematic. All .wav files were converted to Vorbis (.ogg) at 96kbps. For short sound effects like block rotation or landing impacts, the audio quality loss is imperceptible on standard browser audio setups, but the file size reduction is massive.

Conclusion

Building high-performance interactive web experiences requires viewing the Godot engine not just as a game framework, but as a heavily customizable front-end rendering pipeline. By treating every megabyte as a precious resource, we can deliver native-like performance directly inside the browser.