Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM Size Optimization Trick #57

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

SaumitraLohokare
Copy link

TLDR;

  • Updated build script to perform the following commands:
    • $ wasm2wat client.wasm > client.wat
    • $ wat2wasm client.wat -o client.wasm
    • $ wasm2wat server.wasm > server.wat
    • $ wat2wasm server.wat -o server.wasm
  • Updated README to add dependency on wabt.

Problem

LLVM bloats the generated wasm binary.

Solution

While learning about WASM and WAT I noticed that if you disassemble the wasm binary using wasm2wat, then compile it again using wat2wasm, it significantly reduces the size of the generated wasm binary.
This is important for online games as smaller binaries take less time to load.

Results

# Before
$ ls -alh *wasm
-rwxr-xr-x 1 saumi saumi 172K Jan 17 00:21 client.wasm
-rwxr-xr-x 1 saumi saumi  82K Jan 17 00:21 server.wasm

# After
$ ls -alh *wasm
-rwxr-xr-x 1 saumi saumi 162K Jan 17 00:43 client.wasm
-rwxr-xr-x 1 saumi saumi  70K Jan 17 00:43 server.wasm

On running the game no issues were noticed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant